sxp 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +9 -9
- data/VERSION +1 -1
- data/lib/sxp/reader.rb +16 -16
- data/lib/sxp/reader/scheme.rb +2 -2
- data/lib/sxp/reader/sparql.rb +13 -11
- data/lib/sxp/writer.rb +2 -2
- metadata +11 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1603515c0b80435ba91e2abe546d4d8ee49e0fcacfb5363dc4b2d4039101a772
|
4
|
+
data.tar.gz: 78ac18aeefd6096694d34e5553554c75cc2ed91691ebcac2ee1c846d5f7e3bb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1c9687564b01f02f0386754eb292e28a42d4ad510de32803eb70fbe79223a92422506ea09047e15fb63a20f1c1f0b8314b06f014a2cc6c26333726e1e5c8b2e
|
7
|
+
data.tar.gz: 7d95e26602c6d1191be8e3562e3a1d53f1add4a66d29a8f82a1389ebc9d23d74965d8b1a813327871a6650be112ed368ee61d985d1d31e3212c3476fec7de940
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ This is a Ruby implementation of a universal [S-expression][] parser.
|
|
10
10
|
* Parses S-expressions in universal, [Scheme][], [Common Lisp][], or
|
11
11
|
[SPARQL][] syntax.
|
12
12
|
* Adds a `#to_sxp` method to Ruby objects.
|
13
|
-
* Compatible with Ruby >= 2.2.2, Rubinius >=
|
13
|
+
* Compatible with Ruby >= 2.2.2, Rubinius >= 3.0, and JRuby 9+.
|
14
14
|
|
15
15
|
## Examples
|
16
16
|
|
@@ -75,7 +75,7 @@ Dependencies
|
|
75
75
|
------------
|
76
76
|
|
77
77
|
* [Ruby](http://ruby-lang.org/) (>= 2.2.2)
|
78
|
-
* [RDF.rb](http://rubygems.org/gems/rdf) (
|
78
|
+
* [RDF.rb](http://rubygems.org/gems/rdf) (~> 3.0), only needed for SPARQL
|
79
79
|
S-expressions
|
80
80
|
|
81
81
|
Installation
|
@@ -91,25 +91,25 @@ Download
|
|
91
91
|
|
92
92
|
To get a local working copy of the development repository, do:
|
93
93
|
|
94
|
-
% git clone git://github.com/
|
94
|
+
% git clone git://github.com/dryruby/sxp.rb.git
|
95
95
|
|
96
96
|
Alternatively, you can download the latest development version as a tarball
|
97
97
|
as follows:
|
98
98
|
|
99
|
-
% wget http://github.com/
|
99
|
+
% wget http://github.com/dryruby/sxp.rb/tarball/master
|
100
100
|
|
101
101
|
Resources
|
102
102
|
---------
|
103
103
|
|
104
|
-
* <http://rubydoc.info/gems/sxp>
|
105
|
-
* <http://github.com/dryruby/sxp>
|
106
|
-
* <http://rubygems.org/gems/sxp>
|
104
|
+
* <http://rubydoc.info/gems/sxp.rb>
|
105
|
+
* <http://github.com/dryruby/sxp.rb>
|
106
|
+
* <http://rubygems.org/gems/sxp.rb>
|
107
107
|
|
108
108
|
Authors
|
109
109
|
-------
|
110
110
|
|
111
111
|
* [Arto Bendiken](https://github.com/bendiken) - <http://ar.to/>
|
112
|
-
* [Gregg Kellogg](http://github.com/gkellogg) - <http://
|
112
|
+
* [Gregg Kellogg](http://github.com/gkellogg) - <http://greggkellogg.net/>
|
113
113
|
|
114
114
|
Contributors
|
115
115
|
------------
|
@@ -125,4 +125,4 @@ information, see <http://unlicense.org/> or the accompanying UNLICENSE file.
|
|
125
125
|
[S-expression]: http://en.wikipedia.org/wiki/S-expression
|
126
126
|
[Scheme]: http://scheme.info/
|
127
127
|
[Common Lisp]: http://en.wikipedia.org/wiki/Common_Lisp
|
128
|
-
[SPARQL]:
|
128
|
+
[SPARQL]: https://jena.apache.org/documentation/notes/sse.html
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
data/lib/sxp/reader.rb
CHANGED
@@ -22,9 +22,9 @@ module SXP
|
|
22
22
|
# @param [Hash{Symbol => Object}] options
|
23
23
|
# See {#read}
|
24
24
|
# @return [Enumerable<Object>]
|
25
|
-
def self.read_url(url, options
|
25
|
+
def self.read_url(url, **options)
|
26
26
|
require 'open-uri'
|
27
|
-
open(url.to_s, 'rb', nil, options) { |io| read_all(io, options) }
|
27
|
+
open(url.to_s, 'rb', nil, **options) { |io| read_all(io, options) }
|
28
28
|
end
|
29
29
|
|
30
30
|
##
|
@@ -51,8 +51,8 @@ module SXP
|
|
51
51
|
# @param [Hash{Symbol => Object}] options
|
52
52
|
# See {#read}
|
53
53
|
# @return [Enumerable<Object>]
|
54
|
-
def self.read_file(filename, options
|
55
|
-
File.open(filename.to_s, 'rb') { |io| read_all(io, options) }
|
54
|
+
def self.read_file(filename, **options)
|
55
|
+
File.open(filename.to_s, 'rb') { |io| read_all(io, **options) }
|
56
56
|
end
|
57
57
|
|
58
58
|
##
|
@@ -62,8 +62,8 @@ module SXP
|
|
62
62
|
# @param [Hash{Symbol => Object}] options
|
63
63
|
# See {#read}
|
64
64
|
# @return [Enumerable<Object>]
|
65
|
-
def self.read_all(input, options
|
66
|
-
self.new(input, options).read_all
|
65
|
+
def self.read_all(input, **options)
|
66
|
+
self.new(input, **options).read_all
|
67
67
|
end
|
68
68
|
|
69
69
|
##
|
@@ -73,8 +73,8 @@ module SXP
|
|
73
73
|
# @param [Hash{Symbol => Object}] options
|
74
74
|
# See {#read}
|
75
75
|
# @return [Object]
|
76
|
-
def self.read(input, options
|
77
|
-
self.new(input, options).read
|
76
|
+
def self.read(input, **options)
|
77
|
+
self.new(input, **options).read
|
78
78
|
end
|
79
79
|
|
80
80
|
##
|
@@ -82,7 +82,7 @@ module SXP
|
|
82
82
|
#
|
83
83
|
# @param [IO, StringIO, String] input
|
84
84
|
# @param [Hash{Symbol => Object}] options
|
85
|
-
def initialize(input, options
|
85
|
+
def initialize(input, **options, &block)
|
86
86
|
@options = options.dup
|
87
87
|
|
88
88
|
case
|
@@ -127,10 +127,10 @@ module SXP
|
|
127
127
|
# @param [Hash{Symbol => Object}] options
|
128
128
|
# See {#read}
|
129
129
|
# @return [Array]
|
130
|
-
def read_all(options
|
130
|
+
def read_all(**options)
|
131
131
|
list = []
|
132
132
|
catch (:eof) do
|
133
|
-
list << read(
|
133
|
+
list << read(eof: :throw, **options) until eof?
|
134
134
|
end
|
135
135
|
list
|
136
136
|
end
|
@@ -145,19 +145,19 @@ module SXP
|
|
145
145
|
# Expected list terminator; it's an error
|
146
146
|
# if another terminator is found
|
147
147
|
# @return [Object]
|
148
|
-
def read(
|
148
|
+
def read(eof: nil, eol: nil, list_term: false, **options)
|
149
149
|
skip_comments
|
150
150
|
token, value = read_token
|
151
151
|
case token
|
152
152
|
when :eof
|
153
|
-
throw :eof if
|
153
|
+
throw :eof if eof == :throw
|
154
154
|
raise EOF, "unexpected end of input"
|
155
155
|
when :list
|
156
156
|
if ndx = self.class.const_get(:LPARENS).index(value)
|
157
|
-
|
158
|
-
read_list(
|
157
|
+
term = self.class.const_get(:RPARENS)[ndx]
|
158
|
+
read_list(term)
|
159
159
|
else
|
160
|
-
throw :eol if
|
160
|
+
throw :eol if eol == :throw && value == list_term
|
161
161
|
raise Error, "unexpected list terminator: ?#{value.chr}"
|
162
162
|
end
|
163
163
|
else value
|
data/lib/sxp/reader/scheme.rb
CHANGED
@@ -26,8 +26,8 @@ module SXP; class Reader
|
|
26
26
|
# @param [IO, StringIO, String] input
|
27
27
|
# @param [Hash{Symbol => Object}] options
|
28
28
|
# @option options [Symbol] :version (:r4rs)
|
29
|
-
def initialize(input,
|
30
|
-
super(input,
|
29
|
+
def initialize(input, version: :r4rs, **options, &block)
|
30
|
+
super(input, version: version, **options, &block)
|
31
31
|
end
|
32
32
|
|
33
33
|
##
|
data/lib/sxp/reader/sparql.rb
CHANGED
@@ -29,7 +29,11 @@ module SXP; class Reader
|
|
29
29
|
# Distinguished variable
|
30
30
|
VAR_ID = /^\?(.*)/
|
31
31
|
# Non-distinguished variable
|
32
|
-
ND_VAR = /^\?(
|
32
|
+
ND_VAR = /^\?(?:[\?\.])(.*)/
|
33
|
+
# Distinguished existential variable
|
34
|
+
EVAR_ID = /^\$(.*)/
|
35
|
+
# Non-distinguished existential variable
|
36
|
+
ND_EVAR = /^\$(?:[\$\.])(.*)/
|
33
37
|
# A QName, subject to expansion to URIs using {PREFIX}
|
34
38
|
PNAME = /([^:]*):(.*)/
|
35
39
|
|
@@ -67,7 +71,7 @@ module SXP; class Reader
|
|
67
71
|
#
|
68
72
|
# @param [IO, StringIO, String] input
|
69
73
|
# @param [Hash{Symbol => Object}] options
|
70
|
-
def initialize(input, options
|
74
|
+
def initialize(input, **options, &block)
|
71
75
|
super { @prefixes = {}; @bnodes = {}; @list_depth = 0 }
|
72
76
|
|
73
77
|
if block_given?
|
@@ -223,8 +227,10 @@ module SXP; class Reader
|
|
223
227
|
when INTEGER then RDF::Literal::Integer.new(buffer)
|
224
228
|
when BNODE_ID then @bnodes[$1] ||= RDF::Node($1)
|
225
229
|
when BNODE_NEW then RDF::Node.new
|
226
|
-
when ND_VAR
|
227
|
-
when VAR_ID then variable($1, true)
|
230
|
+
when ND_VAR then variable($1, distinguished: false)
|
231
|
+
when VAR_ID then variable($1, distinguished: true)
|
232
|
+
when ND_EVAR then variable($1, existential: true, distinguished: false)
|
233
|
+
when EVAR_ID then variable($1, existential: true, distinguished: true)
|
228
234
|
else buffer.to_sym
|
229
235
|
end
|
230
236
|
end
|
@@ -251,20 +257,16 @@ module SXP; class Reader
|
|
251
257
|
# is a disinguished or non-distinguished variable. Non-distinguished
|
252
258
|
# variables are effectively the same as BNodes.
|
253
259
|
# @return [RDF::Query::Variable]
|
254
|
-
def variable(id, distinguished
|
260
|
+
def variable(id, distinguished: true, existential: false)
|
255
261
|
id = nil if id.to_s.empty?
|
256
262
|
|
257
263
|
if id
|
258
264
|
@vars ||= {}
|
259
265
|
@vars[id] ||= begin
|
260
|
-
|
261
|
-
v.distinguished = distinguished
|
262
|
-
v
|
266
|
+
RDF::Query::Variable.new(id, distinguished: distinguished, existential: existential)
|
263
267
|
end
|
264
268
|
else
|
265
|
-
|
266
|
-
v.distinguished = distinguished
|
267
|
-
v
|
269
|
+
RDF::Query::Variable.new(distinguished: distinguished, existential: existential)
|
268
270
|
end
|
269
271
|
end
|
270
272
|
end # SPARQL
|
data/lib/sxp/writer.rb
CHANGED
@@ -107,8 +107,8 @@ class Float
|
|
107
107
|
# @return [String]
|
108
108
|
def to_sxp
|
109
109
|
case
|
110
|
-
when nan? then 'nan.'
|
111
|
-
when infinite? then (infinite? > 0 ? '+inf.' : '-inf.')
|
110
|
+
when nan? then 'nan.0'
|
111
|
+
when infinite? then (infinite? > 0 ? '+inf.0' : '-inf.0')
|
112
112
|
else to_s
|
113
113
|
end
|
114
114
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sxp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -17,48 +17,42 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '3.
|
20
|
+
version: '3.8'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '3.
|
27
|
+
version: '3.8'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: yard
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 0.9.18
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 0.9.18
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rdf
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '2.2'
|
49
|
-
- - "<"
|
46
|
+
- - "~>"
|
50
47
|
- !ruby/object:Gem::Version
|
51
|
-
version: '
|
48
|
+
version: '3.0'
|
52
49
|
type: :runtime
|
53
50
|
prerelease: false
|
54
51
|
version_requirements: !ruby/object:Gem::Requirement
|
55
52
|
requirements:
|
56
|
-
- - "
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version: '2.2'
|
59
|
-
- - "<"
|
53
|
+
- - "~>"
|
60
54
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
55
|
+
version: '3.0'
|
62
56
|
description: Universal S-expression parser with specific support for Common Lisp,
|
63
57
|
Scheme, and RDF/SPARQL
|
64
58
|
email:
|
@@ -113,8 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
107
|
- !ruby/object:Gem::Version
|
114
108
|
version: '0'
|
115
109
|
requirements: []
|
116
|
-
|
117
|
-
rubygems_version: 2.6.14
|
110
|
+
rubygems_version: 3.0.2
|
118
111
|
signing_key:
|
119
112
|
specification_version: 4
|
120
113
|
summary: A pure-Ruby implementation of a universal S-expression parser.
|