sxp 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +4 -4
- data/VERSION +1 -1
- data/lib/sxp.rb +1 -1
- data/lib/sxp/generator.rb +2 -2
- data/lib/sxp/list.rb +2 -2
- data/lib/sxp/pair.rb +2 -2
- data/lib/sxp/reader.rb +2 -2
- data/lib/sxp/reader/basic.rb +8 -8
- data/lib/sxp/reader/common_lisp.rb +2 -2
- data/lib/sxp/reader/extended.rb +5 -5
- data/lib/sxp/reader/scheme.rb +8 -8
- data/lib/sxp/reader/sparql.rb +12 -8
- data/lib/sxp/version.rb +1 -1
- metadata +2 -2
data/README
CHANGED
@@ -19,7 +19,7 @@ Examples
|
|
19
19
|
|
20
20
|
require 'sxp'
|
21
21
|
|
22
|
-
### Parsing S-expressions
|
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
|
38
|
+
### Parsing Scheme S-expressions
|
39
39
|
|
40
40
|
SXP::Reader::Scheme.read %q((and #t #f)) #=> [:and, true, false]
|
41
41
|
|
42
|
-
### Parsing
|
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
|
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.
|
1
|
+
0.0.8
|
data/lib/sxp.rb
CHANGED
data/lib/sxp/generator.rb
CHANGED
data/lib/sxp/list.rb
CHANGED
data/lib/sxp/pair.rb
CHANGED
data/lib/sxp/reader.rb
CHANGED
data/lib/sxp/reader/basic.rb
CHANGED
@@ -2,12 +2,12 @@ module SXP; class Reader
|
|
2
2
|
##
|
3
3
|
# A basic S-expression parser.
|
4
4
|
class Basic < Reader
|
5
|
-
LPARENS = [?(]
|
6
|
-
RPARENS = [?)]
|
7
|
-
ATOM = /^[^\s()]
|
8
|
-
RATIONAL = /^([+-]?\d+)\/(\d+)
|
9
|
-
DECIMAL = /^[+-]?(\d*)?\.\d
|
10
|
-
INTEGER = /^[+-]?\d
|
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 #
|
76
|
-
end; end #
|
75
|
+
end # Basic
|
76
|
+
end; end # SXP::Reader
|
data/lib/sxp/reader/extended.rb
CHANGED
@@ -2,9 +2,9 @@ module SXP; class Reader
|
|
2
2
|
##
|
3
3
|
# An extended S-expression parser.
|
4
4
|
class Extended < Basic
|
5
|
-
LPARENS = [?(, ?[]
|
6
|
-
RPARENS = [?), ?]]
|
7
|
-
ATOM = /^[^\s()\[\]]
|
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 #
|
30
|
-
end; end #
|
29
|
+
end # Extended
|
30
|
+
end; end # SXP::Reader
|
data/lib/sxp/reader/scheme.rb
CHANGED
@@ -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
|
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+)
|
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 #
|
64
|
-
end; end #
|
63
|
+
end # Scheme
|
64
|
+
end; end # SXP::Reader
|
data/lib/sxp/reader/sparql.rb
CHANGED
@@ -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]*)
|
12
|
-
BNODE_NEW = /^_
|
13
|
-
|
14
|
-
|
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
|
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 #
|
82
|
-
end; end #
|
85
|
+
end # SPARQL
|
86
|
+
end; end # SXP::Reader
|
data/lib/sxp/version.rb
CHANGED