sxp 1.0.0 → 1.2.0
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.
- checksums.yaml +5 -5
- data/AUTHORS +1 -1
- data/README.md +204 -45
- data/UNLICENSE +1 -1
- data/VERSION +1 -1
- data/bin/sxp2json +2 -2
- data/bin/sxp2rdf +2 -2
- data/bin/sxp2xml +2 -2
- data/bin/sxp2yaml +2 -2
- data/lib/sxp/extensions.rb +304 -4
- data/lib/sxp/generator.rb +31 -8
- data/lib/sxp/pair.rb +2 -2
- data/lib/sxp/reader/common_lisp.rb +9 -6
- data/lib/sxp/reader/scheme.rb +7 -7
- data/lib/sxp/reader/sparql.rb +21 -23
- data/lib/sxp/reader.rb +18 -18
- data/lib/sxp.rb +9 -24
- metadata +46 -21
- data/lib/sxp/writer.rb +0 -216
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8ac25f66cc3d44ef1ea0ee37141ce092c9740ada5d58e000472043ed0e53dec7
|
4
|
+
data.tar.gz: 3969e76131d5e12a512a182ba9f03de3f1dcc098b60cd067089f0d75443117ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da0445f22b06f2ed5cb31a44dd37bc4c49a078205335f420857b1105b30f1d95296254e4d7f0ce80c5d4779862f0792c45e409758c893eb0131eced633df243c
|
7
|
+
data.tar.gz: f8018ae5ffb2740cf12e0ca28f67c4f3b92dd466b0a2a2db73ed896f6fdb801a4a3148daf3c575474890db74d278ad2cecd114336fd9f85e021555456ea7393b
|
data/AUTHORS
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
* Arto Bendiken <arto@bendiken.net>
|
2
|
-
* Gregg Kellogg <gregg@
|
2
|
+
* Gregg Kellogg <gregg@greggkellogg.net>
|
data/README.md
CHANGED
@@ -1,18 +1,169 @@
|
|
1
|
-
#SXP.rb: S-Expressions for Ruby
|
1
|
+
# SXP.rb: S-Expressions for Ruby
|
2
2
|
|
3
3
|
This is a Ruby implementation of a universal [S-expression][] parser.
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
[](https:/badge.fury.io/rb/sxp)
|
6
|
+
[](https://github.com/dryruby/sxp.rb/actions?query=workflow%3ACI)
|
7
|
+
[](https://coveralls.io/r/dryruby/sxp.rb?branch=develop)
|
7
8
|
|
8
|
-
##Features
|
9
|
+
## Features
|
9
10
|
|
10
11
|
* Parses S-expressions in universal, [Scheme][], [Common Lisp][], or
|
11
12
|
[SPARQL][] syntax.
|
12
13
|
* Adds a `#to_sxp` method to Ruby objects.
|
13
|
-
* Compatible with Ruby
|
14
|
-
|
15
|
-
##
|
14
|
+
* Compatible with Ruby >= 2.6, Rubinius >= 3.0, and JRuby 9+.
|
15
|
+
|
16
|
+
## Basic syntax
|
17
|
+
|
18
|
+
S-Expressions derive from LISP, and include some basic datatypes common to all variants:
|
19
|
+
|
20
|
+
<dl>
|
21
|
+
<dt>Pairs</dt>
|
22
|
+
<dd>Of the form <code>(2 . 3)</code></dd>
|
23
|
+
<dt>Lists</dt>
|
24
|
+
<dd>Of the form <code>(1 (2 3))</code></dd>
|
25
|
+
<dt>Symbols</dt>
|
26
|
+
<dd>Of the form <code>with-hyphen ?@!$ a\ symbol\ with\ spaces</code></dd>
|
27
|
+
<dt>Strings</dt>
|
28
|
+
<dd>Of the form <code>"Hello, world!"</code><br/>
|
29
|
+
Strings may include the following special characters:
|
30
|
+
<ul>
|
31
|
+
<li><code>\b</code> — Backspace</li>
|
32
|
+
<li><code>\f</code> — Form Feed</li>
|
33
|
+
<li><code>\n</code> — New Line</li>
|
34
|
+
<li><code>\r</code> — Carriage Return</li>
|
35
|
+
<li><code>\t</code> — Horizontal Tab</li>
|
36
|
+
<li><code>\u<i>xxxx</i></code> — 2-byte Unicode character escape</li>
|
37
|
+
<li><code>\U<i>xxxxxxxx</i></code> — 4-byte Unicode character escape</li>
|
38
|
+
<li><code>\"</code> — Double-quote character</li>
|
39
|
+
<li><code>\\</code> — Backspace</li>
|
40
|
+
</ul>
|
41
|
+
Additionally, any other character may follow <code>\</code>, representing the character itself.
|
42
|
+
</dd>
|
43
|
+
<dt>Characters</dt>
|
44
|
+
<dd>Of the form <code>...</code></dd>
|
45
|
+
<dt>Integers</dt>
|
46
|
+
<dd>Of the form <code>-9876543210</code></dd>
|
47
|
+
<dt>Floating-point numbers</dt>
|
48
|
+
<dd>Of the form <code>-0.0 6.28318 6.022e23</code></dd>
|
49
|
+
<dt>Rationals</dt>
|
50
|
+
<dd>Of the form <code>1/3</code></dd>
|
51
|
+
</dl>
|
52
|
+
|
53
|
+
Additionally, variation-specific formats support additional datatypes:
|
54
|
+
|
55
|
+
### Scheme
|
56
|
+
|
57
|
+
In addition to the standard datatypes, the Scheme dialect supports the following:
|
58
|
+
|
59
|
+
<dl>
|
60
|
+
<dt>Lists</dt>
|
61
|
+
<dd>In addition to <code>( ... )</code>, a square bracket pair may be used for reading lists of the form <code>[ ... ]</code>.
|
62
|
+
</dd>
|
63
|
+
<dt>Comments</dt>
|
64
|
+
<dd>A comment starts with <code>;</code> and continues to the end of the line.
|
65
|
+
<dt>Sharp character sequences</dt>
|
66
|
+
<dd>Such as <code>#t</code>, <code>#n</code>, and <code>#xXXX</code>.<br>
|
67
|
+
<ul>
|
68
|
+
<li><code>#n</code> — Null</li>
|
69
|
+
<li><code>#f</code> — False</li>
|
70
|
+
<li><code>#t</code> — True</li>
|
71
|
+
<li><code>#b<i>BBB</i></code> — Binary number</li>
|
72
|
+
<li><code>#o<i>OOO</i></code> — Octal number</li>
|
73
|
+
<li><code>#d<i>DDD</i></code> — Decimal number</li>
|
74
|
+
<li><code>#x<i>XXX</i></code> — Hexadecimal number</li>
|
75
|
+
<li><code>#\<i>C</i></code> — A single Unicode character</li>
|
76
|
+
<li><code>#\space</code> — A space character</li>
|
77
|
+
<li><code>#\newline</code> — A newline character</li>
|
78
|
+
<li><code>#;</code> — Skipped character</li>
|
79
|
+
<li><code>#!</code> — Skipped to end of line</li>
|
80
|
+
</ul>
|
81
|
+
</dd>
|
82
|
+
</dl>
|
83
|
+
|
84
|
+
### Common Lisp
|
85
|
+
|
86
|
+
In addition to the standard datatypes, the Common Lisp dialect supports the following:
|
87
|
+
|
88
|
+
<dl>
|
89
|
+
<dt>Comments</dt>
|
90
|
+
<dd>A comment starts with <code>;</code> and continues to the end of the line.
|
91
|
+
<dt>Symbols</dt>
|
92
|
+
<dd>In addition to base symbols, any character sequence delimited by <code>|</code> is treated as a symbol.</dd>
|
93
|
+
<dt>Sharp character sequences</dt>
|
94
|
+
<dd>Such as <code>#t</code>, <code>#n</code>, and <code>#xXXX</code>.<br>
|
95
|
+
<ul>
|
96
|
+
<li><code>#b<i>BBB</i></code> — Binary number</li>
|
97
|
+
<li><code>#o<i>OOO</i></code> — Octal number</li>
|
98
|
+
<li><code>#x<i>XXX</i></code> — Hexadecimal number</li>
|
99
|
+
<li><code>#C</code> — A single Unicode character</li>
|
100
|
+
<li><code>#\newline</code> — A newline character</li>
|
101
|
+
<li><code>#\space</code> — A space character</li>
|
102
|
+
<li><code>#\backspace</code> — A backspace character</li>
|
103
|
+
<li><code>#\tab</code> — A tab character</li>
|
104
|
+
<li><code>#\linefeed</code> — A linefeed character</li>
|
105
|
+
<li><code>#\page</code> — A page feed character</li>
|
106
|
+
<li><code>#\return</code> — A carriage return character</li>
|
107
|
+
<li><code>#\rubout</code> — A rubout character</li>
|
108
|
+
<li><code>#'<i>function</i></code> — A function definition</li>
|
109
|
+
</ul>
|
110
|
+
</dd>
|
111
|
+
</dl>
|
112
|
+
|
113
|
+
### SPARQL/RDF
|
114
|
+
|
115
|
+
In addition to the standard datatypes, the SPARQL dialect supports the following:
|
116
|
+
|
117
|
+
<dl>
|
118
|
+
<dt>Lists</dt>
|
119
|
+
<dd>In addition to <code>( ... )</code>, a square bracket pair may be used for reading lists of the form <code>[ ... ]</code>.
|
120
|
+
</dd>
|
121
|
+
<dt>Comments</dt>
|
122
|
+
<dd>A comment starts with <code>#</code> or <code>;</code> and continues to the end of the line.
|
123
|
+
<dt>Literals</dt>
|
124
|
+
<dd>Strings are interpreted as an RDF Literal with datatype <code>xsd:string</code>. It can be followed by <code>@<i>lang</i></code> to create a language-tagged string, or <code>^^<i>IRI</i></code> to create a datatyped-literal. Examples:
|
125
|
+
<ul>
|
126
|
+
<li><code>"a plain literal"</code></li>
|
127
|
+
<li><code>"a literal with a language"@en</code></li>
|
128
|
+
<li><code>"a typed literal"^^<http://example/></code></li>
|
129
|
+
<li><code>"a typed literal with a PNAME"^^xsd:string</code></li>
|
130
|
+
</ul>
|
131
|
+
</dd>
|
132
|
+
<dt>IRIs</dt>
|
133
|
+
<dd>An IRI is formed as in SPARQL, either enclosed by <code><...></code>, or having the form of a <code>PNAME</code>. If a <var>base iri</var> is defined in a containing <var>base</var> expression, IRIs using the <code><...></code> are resolved against that base iri. If the <code>PNAME</code> form is used, the prefix must be defined in a containing <var>prefix</var> expression. Examples:
|
134
|
+
<ul>
|
135
|
+
<li><code><http://example/foo></code></li>
|
136
|
+
<li><code>(base <http://example.com> <foo>)</code></li>
|
137
|
+
<li><code>(prefix ((foo: <http://example.com/>)) foo:bar)</code></li>
|
138
|
+
<li><code>a</code> # synonym for rdf:type</li>
|
139
|
+
</ul>
|
140
|
+
</dd>
|
141
|
+
<dt>Blank Nodes</dt>
|
142
|
+
<dd>An blank node is formed as in SPARQL. Examples:
|
143
|
+
<ul>
|
144
|
+
<li><code>_:</code></li>
|
145
|
+
<li><code>_:id</code></li>
|
146
|
+
</ul>
|
147
|
+
</dd>
|
148
|
+
<dt>Variables</dt>
|
149
|
+
<dd>A SPARQL variable is defined using either <code>?</code> or <code>$</code> prefixes, as in SPARQL. Examples:
|
150
|
+
<ul>
|
151
|
+
<li><code>?var</code></li>
|
152
|
+
<li><code>$var</code></li>
|
153
|
+
</ul>
|
154
|
+
</dd>
|
155
|
+
<dt>Numbers and booleans</dt>
|
156
|
+
<dd>As with SPARQL. Examples:
|
157
|
+
<ul>
|
158
|
+
<li>true, false</li>
|
159
|
+
<li>123, -18</li>
|
160
|
+
<li>123.0, 456.</li>
|
161
|
+
<li>1.0e0, 1.0E+6</li>
|
162
|
+
</ul>
|
163
|
+
</dd>
|
164
|
+
</dl>
|
165
|
+
|
166
|
+
## Examples
|
16
167
|
|
17
168
|
require 'sxp'
|
18
169
|
|
@@ -44,15 +195,15 @@ This is a Ruby implementation of a universal [S-expression][] parser.
|
|
44
195
|
|
45
196
|
require 'rdf'
|
46
197
|
|
47
|
-
SXP::Reader::SPARQL.read %q((base <
|
198
|
+
SXP::Reader::SPARQL.read %q((base <https://ar.to/>)) #=> [:base, RDF::URI('https://ar.to/')]
|
48
199
|
|
49
200
|
### Writing an SXP with formatting
|
50
201
|
|
51
202
|
SXP::Generator.print([:and, true, false]) #=> (and #t #f)
|
52
203
|
|
53
|
-
##Documentation
|
204
|
+
## Documentation
|
54
205
|
|
55
|
-
*
|
206
|
+
* Full documentation available on [RubyDoc](https:/rubydoc.info/gems/sxp/file/README.md)
|
56
207
|
|
57
208
|
* {SXP}
|
58
209
|
|
@@ -71,62 +222,70 @@ This is a Ruby implementation of a universal [S-expression][] parser.
|
|
71
222
|
### Generating SXP
|
72
223
|
* {SXP::Generator}
|
73
224
|
|
74
|
-
Dependencies
|
75
|
-
------------
|
225
|
+
# Dependencies
|
76
226
|
|
77
|
-
* [Ruby](
|
78
|
-
* [RDF.rb](
|
227
|
+
* [Ruby](https:/ruby-lang.org/) (>= 2.6)
|
228
|
+
* [RDF.rb](https:/rubygems.org/gems/rdf) (~> 3.2), only needed for SPARQL
|
79
229
|
S-expressions
|
80
230
|
|
81
|
-
Installation
|
82
|
-
------------
|
231
|
+
# Installation
|
83
232
|
|
84
|
-
The recommended installation method is via [RubyGems](
|
233
|
+
The recommended installation method is via [RubyGems](https:/rubygems.org/).
|
85
234
|
To install the latest official release of the SXP.rb gem, do:
|
86
235
|
|
87
236
|
% [sudo] gem install sxp
|
88
237
|
|
89
|
-
Download
|
90
|
-
--------
|
238
|
+
## Download
|
91
239
|
|
92
240
|
To get a local working copy of the development repository, do:
|
93
241
|
|
94
|
-
% git clone git://github.com/
|
242
|
+
% git clone git://github.com/dryruby/sxp.rb.git
|
95
243
|
|
96
244
|
Alternatively, you can download the latest development version as a tarball
|
97
245
|
as follows:
|
98
246
|
|
99
|
-
% wget
|
247
|
+
% wget https:/github.com/dryruby/sxp.rb/tarball/master
|
100
248
|
|
101
|
-
Resources
|
102
|
-
---------
|
249
|
+
## Resources
|
103
250
|
|
104
|
-
* <
|
105
|
-
* <
|
106
|
-
* <
|
107
|
-
* <http://rubygems.org/gems/sxp>
|
108
|
-
* <http://rubyforge.org/projects/sxp/>
|
109
|
-
* <http://raa.ruby-lang.org/project/sxp>
|
251
|
+
* <https://rubydoc.info/gems/sxp.rb>
|
252
|
+
* <https://github.com/dryruby/sxp.rb>
|
253
|
+
* <https://rubygems.org/gems/sxp.rb>
|
110
254
|
|
111
|
-
Authors
|
112
|
-
-------
|
255
|
+
## Authors
|
113
256
|
|
114
|
-
* [Arto Bendiken](https://github.com/
|
115
|
-
* [Gregg Kellogg](
|
257
|
+
* [Arto Bendiken](https://github.com/artob) - <https://ar.to/>
|
258
|
+
* [Gregg Kellogg](https://github.com/gkellogg) - <https://greggkellogg.net/>
|
116
259
|
|
117
|
-
Contributors
|
118
|
-
------------
|
260
|
+
## Contributors
|
119
261
|
|
120
|
-
* [Ben Lavender](https://github.com/bhuga) - <
|
262
|
+
* [Ben Lavender](https://github.com/bhuga) - <https://bhuga.net/>
|
121
263
|
|
122
|
-
|
123
|
-
|
264
|
+
## Contributing
|
265
|
+
This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration.
|
124
266
|
|
125
|
-
|
126
|
-
|
267
|
+
* Do your best to adhere to the existing coding conventions and idioms.
|
268
|
+
* Don't use hard tabs, and don't leave trailing whitespace on any line.
|
269
|
+
* Do document every method you add using [YARD][] annotations. Read the
|
270
|
+
[tutorial][YARD-GS] or just look at the existing code for examples.
|
271
|
+
* Don't touch the `.gemspec`, `VERSION` or `AUTHORS` files. If you need to
|
272
|
+
change them, do so on your private branch only.
|
273
|
+
* Do feel free to add yourself to the `CREDITS` file and the corresponding
|
274
|
+
list in the the `README`. Alphabetical order applies.
|
275
|
+
* Do note that in order for us to merge any non-trivial changes (as a rule
|
276
|
+
of thumb, additions larger than about 15 lines of code), we need an
|
277
|
+
explicit [public domain dedication][PDD] on record from you,
|
278
|
+
which you will be asked to agree to on the first commit to a repo within the organization.
|
127
279
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
280
|
+
## License
|
281
|
+
|
282
|
+
SXP.rb is free and unencumbered public domain software. For more
|
283
|
+
information, see <https://unlicense.org/> or the accompanying UNLICENSE file.
|
284
|
+
|
285
|
+
[S-expression]: https://en.wikipedia.org/wiki/S-expression
|
286
|
+
[Scheme]: https://scheme.info/
|
287
|
+
[Common Lisp]: https://en.wikipedia.org/wiki/Common_Lisp
|
288
|
+
[SPARQL]: https://jena.apache.org/documentation/notes/sse.html
|
289
|
+
[YARD]: https://yardoc.org/
|
290
|
+
[YARD-GS]: https://rubydoc.info/docs/yard/file/docs/GettingStarted.md
|
291
|
+
[PDD]: https://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
|
data/UNLICENSE
CHANGED
@@ -21,4 +21,4 @@ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
21
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
22
|
OTHER DEALINGS IN THE SOFTWARE.
|
23
23
|
|
24
|
-
For more information, please refer to <
|
24
|
+
For more information, please refer to <https:/unlicense.org/>
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/bin/sxp2json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$::unshift(File.expand_path("../../lib", __FILE__))
|
3
3
|
require 'sxp'
|
4
4
|
|
5
5
|
abort "Usage: #{File.basename($0)} input.sxp > output.json" if ARGV.empty?
|
data/bin/sxp2rdf
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$::unshift(File.expand_path("../../lib", __FILE__))
|
3
3
|
require 'sxp'
|
4
4
|
|
5
5
|
abort "Usage: #{File.basename($0)} input.sxp > output.rdf" if ARGV.empty?
|
data/bin/sxp2xml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$::unshift(File.expand_path("../../lib", __FILE__))
|
3
3
|
require 'sxp'
|
4
4
|
|
5
5
|
abort "Usage: #{File.basename($0)} input.sxp > output.xml" if ARGV.empty?
|
data/bin/sxp2yaml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$::unshift(File.expand_path("../../lib", __FILE__))
|
3
3
|
require 'sxp'
|
4
4
|
|
5
5
|
abort "Usage: #{File.basename($0)} input.sxp > output.yaml" if ARGV.empty?
|