sxp 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -19,7 +19,7 @@ Examples
19
19
 
20
20
  require 'sxp'
21
21
 
22
- ### Parsing S-expressions using universal syntax
22
+ ### Parsing basic S-expressions
23
23
 
24
24
  SXP.read "(* 6 7)" #=> [:*, 6, 7]
25
25
 
@@ -35,15 +35,15 @@ Examples
35
35
  1,
36
36
  [:*, :n, [:fact, [:-, :n, 1]]]]]
37
37
 
38
- ### Parsing S-expressions using Scheme syntax
38
+ ### Parsing Scheme S-expressions
39
39
 
40
40
  SXP::Reader::Scheme.read %q((and #t #f)) #=> [:and, true, false]
41
41
 
42
- ### Parsing S-expressions using Common Lisp syntax
42
+ ### Parsing Common Lisp S-expressions
43
43
 
44
44
  SXP::Reader::CommonLisp.read %q((or t nil)) #=> [:or, true, nil]
45
45
 
46
- ### Parsing S-expressions using SPARQL syntax
46
+ ### Parsing SPARQL S-expressions
47
47
 
48
48
  SXP::Reader::SPARQL.read %q((base <http://ar.to/>)) #=> [:base, RDF::URI('http://ar.to/')]
49
49
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
data/lib/sxp.rb CHANGED
@@ -85,4 +85,4 @@ module SXP
85
85
  alias_method :parse_uri, :read_url # @deprecated
86
86
  alias_method :read_uri, :read_url # @deprecated
87
87
  end
88
- end # module SXP
88
+ end # SXP
data/lib/sxp/generator.rb CHANGED
@@ -86,5 +86,5 @@ module SXP
86
86
  def decrease_indent!
87
87
  @indent -= 1
88
88
  end
89
- end # class Generator
90
- end # module SXP
89
+ end # Generator
90
+ end # SXP
data/lib/sxp/list.rb CHANGED
@@ -498,5 +498,5 @@ module SXP
498
498
  def values_at(*selector)
499
499
  self.class.new(to_a.values_at(*selector))
500
500
  end
501
- end # class List
502
- end # module SXP
501
+ end # List
502
+ end # SXP
data/lib/sxp/pair.rb CHANGED
@@ -60,5 +60,5 @@ module SXP
60
60
  "(#{head.inspect} . #{tail.inspect})"
61
61
  end
62
62
  end
63
- end # class Pair
64
- end # module SXP
63
+ end # Pair
64
+ end # SXP
data/lib/sxp/reader.rb CHANGED
@@ -258,5 +258,5 @@ module SXP
258
258
  def eof?
259
259
  @input.eof?
260
260
  end
261
- end # class Reader
262
- end # module SXP
261
+ end # Reader
262
+ end # SXP
@@ -2,12 +2,12 @@ module SXP; class Reader
2
2
  ##
3
3
  # A basic S-expression parser.
4
4
  class Basic < Reader
5
- LPARENS = [?(].freeze
6
- RPARENS = [?)].freeze
7
- ATOM = /^[^\s()]+/.freeze
8
- RATIONAL = /^([+-]?\d+)\/(\d+)$/.freeze
9
- DECIMAL = /^[+-]?(\d*)?\.\d*$/.freeze
10
- INTEGER = /^[+-]?\d+$/.freeze
5
+ LPARENS = [?(]
6
+ RPARENS = [?)]
7
+ ATOM = /^[^\s()]+/
8
+ RATIONAL = /^([+-]?\d+)\/(\d+)$/
9
+ DECIMAL = /^[+-]?(\d*)?\.\d*$/
10
+ INTEGER = /^[+-]?\d+$/
11
11
 
12
12
  ##
13
13
  # @return [Object]
@@ -72,5 +72,5 @@ module SXP; class Reader
72
72
  buffer << read_char while !eof? && peek_char.chr =~ grammar
73
73
  buffer
74
74
  end
75
- end # class Basic
76
- end; end # class SXP::Reader
75
+ end # Basic
76
+ end; end # SXP::Reader
@@ -123,5 +123,5 @@ module SXP; class Reader
123
123
  end
124
124
  end
125
125
  end
126
- end # class CommonLisp
127
- end; end # class SXP::Reader
126
+ end # CommonLisp
127
+ end; end # SXP::Reader
@@ -2,9 +2,9 @@ module SXP; class Reader
2
2
  ##
3
3
  # An extended S-expression parser.
4
4
  class Extended < Basic
5
- LPARENS = [?(, ?[].freeze
6
- RPARENS = [?), ?]].freeze
7
- ATOM = /^[^\s()\[\]]+/.freeze
5
+ LPARENS = [?(, ?[]
6
+ RPARENS = [?), ?]]
7
+ ATOM = /^[^\s()\[\]]+/
8
8
 
9
9
  ##
10
10
  # @return [Object]
@@ -26,5 +26,5 @@ module SXP; class Reader
26
26
  end
27
27
  end
28
28
  end
29
- end # class Extended
30
- end; end # class SXP::Reader
29
+ end # Extended
30
+ end; end # SXP::Reader
@@ -4,12 +4,12 @@ module SXP; class Reader
4
4
  #
5
5
  # @see http://people.csail.mit.edu/jaffer/r4rs_9.html#SEC65
6
6
  class Scheme < Extended
7
- DECIMAL = /^[+-]?(\d*)?\.\d*$/.freeze
8
- INTEGER_BASE_2 = /^[+-]?[01]+$/.freeze
9
- INTEGER_BASE_8 = /^[+-]?[0-7]+$/.freeze
10
- INTEGER_BASE_10 = /^[+-]?\d+$/.freeze
11
- INTEGER_BASE_16 = /^[+-]?[\da-z]+$/i.freeze
12
- RATIONAL = /^([+-]?\d+)\/(\d+)$/.freeze
7
+ DECIMAL = /^[+-]?(\d*)?\.\d*$/
8
+ INTEGER_BASE_2 = /^[+-]?[01]+$/
9
+ INTEGER_BASE_8 = /^[+-]?[0-7]+$/
10
+ INTEGER_BASE_10 = /^[+-]?\d+$/
11
+ INTEGER_BASE_16 = /^[+-]?[\da-z]+$/i
12
+ RATIONAL = /^([+-]?\d+)\/(\d+)$/
13
13
 
14
14
  ##
15
15
  # Initializes the reader.
@@ -60,5 +60,5 @@ module SXP; class Reader
60
60
  else raise Error, "invalid sharp-sign read syntax: ##{char.chr}"
61
61
  end
62
62
  end
63
- end # class Scheme
64
- end; end # class SXP::Reader
63
+ end # Scheme
64
+ end; end # SXP::Reader
@@ -8,10 +8,12 @@ module SXP; class Reader
8
8
  #
9
9
  # @see http://openjena.org/wiki/SSE
10
10
  class SPARQL < Extended
11
- BNODE_ID = /^_:([A-Za-z][A-Za-z0-9]*)/.freeze # FIXME
12
- BNODE_NEW = /^_:$/.freeze
13
- VARIABLE = /^\?([A-Za-z][A-Za-z0-9]*)/.freeze # FIXME
14
- URIREF = /^<([^>]+)>/.freeze
11
+ BNODE_ID = /^_:([A-Za-z][A-Za-z0-9]*)/ # FIXME
12
+ BNODE_NEW = /^_:$/
13
+ VAR_ID = /^\?([A-Za-z][A-Za-z0-9]*)/ # FIXME
14
+ VAR_GEN = /^\?\?([0-9]+)/
15
+ VAR_NEW = '??'
16
+ URIREF = /^<([^>]+)>/
15
17
 
16
18
  ##
17
19
  # @return [Object]
@@ -44,7 +46,7 @@ module SXP; class Reader
44
46
  def read_rdf_uri
45
47
  buffer = String.new
46
48
  skip_char # '<'
47
- return :< if (char = peek_char).nil? || char !~ ATOM # FIXME: nasty special case for '< symbol
49
+ return :< if (char = peek_char).nil? || char.chr !~ ATOM # FIXME: nasty special case for '< symbol
48
50
  until peek_char == ?>
49
51
  buffer << read_char # TODO: unescaping
50
52
  end
@@ -61,7 +63,9 @@ module SXP; class Reader
61
63
  when INTEGER then RDF::Literal(Integer(buffer))
62
64
  when BNODE_ID then RDF::Node($1)
63
65
  when BNODE_NEW then RDF::Node.new
64
- when VARIABLE then RDF::Query::Variable.new($1)
66
+ when VAR_ID then RDF::Query::Variable.new($1)
67
+ when VAR_GEN then RDF::Query::Variable.new("?#{$1}") # FIXME?
68
+ when VAR_NEW then RDF::Query::Variable.new
65
69
  else buffer.to_sym
66
70
  end
67
71
  end
@@ -78,5 +82,5 @@ module SXP; class Reader
78
82
  end
79
83
  end
80
84
  end
81
- end # class SPARQL
82
- end; end # class SXP::Reader
85
+ end # SPARQL
86
+ end; end # SXP::Reader
data/lib/sxp/version.rb CHANGED
@@ -2,7 +2,7 @@ module SXP
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 7
5
+ TINY = 8
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, EXTRA].compact.join('.')
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 7
9
- version: 0.0.7
8
+ - 8
9
+ version: 0.0.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Arto Bendiken