sxp 1.2.4 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0def5550a64e4c23fadfa0255347b32d74e8d263116a9bc855d6ad8113f75a0
4
- data.tar.gz: 837c79054b8cdd73faf80283dae018f8f10a8ec29665ab4742cce074e18a3d75
3
+ metadata.gz: '058a4a32d0bc8f49d4032efeeaa309d563d0309304c2c9baae1dc3bcec9e240b'
4
+ data.tar.gz: 6cf5ed0d766a7fe82bf01c888ed1453f4d4e03b0931963b8989a766c0e1f5959
5
5
  SHA512:
6
- metadata.gz: 0fbc0c79aaef7f33b2cedb1bfe56293477a22838897dce9e17bf7f8fa4db1cd15e234109b58e473d711b5288eb0be340d34c6867d13ed183e51f46a1f4a5c06a
7
- data.tar.gz: c68c05c3fb3e37327c686416867d3bd73dc054867f016dfde6e57e70a1e8e1645e253fa9e8b32ffbc4ce6baabf26b84b559307d63c7cb457b5cfc9a210d71498
6
+ metadata.gz: 1c9f61f82bbc7627edbdda238876e917149a5e6ca6818435f7f52f066ccb776474af0bd1718fe50ce6092fb6c1f16f1efe3610105561402abb656a46860e359b
7
+ data.tar.gz: bc47c210990f6ec08a0d134329d101e249669c61b6d354e4454cdaf9ecedeec99974c084356b7ba41b3a1c4f48dd3e5ff5c6caa9d1d5a9babea81e485e6f88c2
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This is a Ruby implementation of a universal [S-expression][] parser.
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/sxp.png)](https:/badge.fury.io/rb/sxp)
5
+ [![Gem Version](https://badge.fury.io/rb/sxp.svg)](https:/badge.fury.io/rb/sxp)
6
6
  [![Build Status](https://github.com/dryruby/sxp.rb/workflows/CI/badge.svg?branch=develop)](https://github.com/dryruby/sxp.rb/actions?query=workflow%3ACI)
7
7
  [![Coverage Status](https://coveralls.io/repos/dryruby/sxp.rb/badge.svg?branch=develop)](https://coveralls.io/r/dryruby/sxp.rb?branch=develop)
8
8
 
@@ -11,7 +11,7 @@ This is a Ruby implementation of a universal [S-expression][] parser.
11
11
  * Parses S-expressions in universal, [Scheme][], [Common Lisp][], or
12
12
  [SPARQL][] syntax.
13
13
  * Adds a `#to_sxp` method to Ruby objects.
14
- * Compatible with Ruby >= 2.6, Rubinius >= 3.0, and JRuby 9+.
14
+ * Compatible with Ruby >= 3.0, Rubinius >= 3.0, and JRuby 9+.
15
15
 
16
16
  ## Basic syntax
17
17
 
@@ -25,7 +25,7 @@ S-Expressions derive from LISP, and include some basic datatypes common to all v
25
25
  <dt>Symbols</dt>
26
26
  <dd>Of the form <code>with-hyphen ?@!$ a\ symbol\ with\ spaces</code></dd>
27
27
  <dt>Strings</dt>
28
- <dd>Of the form <code>"Hello, world!"</code><br/>
28
+ <dd>Of the form <code>"Hello, world!"</code> or <code>'Hello, world!'</code><br/>
29
29
  Strings may include the following special characters:
30
30
  <ul>
31
31
  <li><code>\b</code> &mdash; Backspace</li>
@@ -36,6 +36,7 @@ S-Expressions derive from LISP, and include some basic datatypes common to all v
36
36
  <li><code>\u<i>xxxx</i></code> &mdash; 2-byte Unicode character escape</li>
37
37
  <li><code>\U<i>xxxxxxxx</i></code> &mdash; 4-byte Unicode character escape</li>
38
38
  <li><code>\"</code> &mdash; Double-quote character</li>
39
+ <li><code>\'</code> &mdash; Single-quote character</li>
39
40
  <li><code>\\</code> &mdash; Backspace</li>
40
41
  </ul>
41
42
  Additionally, any other character may follow <code>\</code>, representing the character itself.
@@ -124,6 +125,7 @@ In addition to the standard datatypes, the SPARQL dialect supports the following
124
125
  <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
126
  <ul>
126
127
  <li><code>"a plain literal"</code></li>
128
+ <li><code>'another plain literal'</code></li>
127
129
  <li><code>"a literal with a language"@en</code></li>
128
130
  <li><code>"a typed literal"^^&lt;http://example/></code></li>
129
131
  <li><code>"a typed literal with a PNAME"^^xsd:string</code></li>
@@ -224,8 +226,8 @@ In addition to the standard datatypes, the SPARQL dialect supports the following
224
226
 
225
227
  # Dependencies
226
228
 
227
- * [Ruby](https:/ruby-lang.org/) (>= 2.6)
228
- * [RDF.rb](https:/rubygems.org/gems/rdf) (~> 3.2), only needed for SPARQL
229
+ * [Ruby](https:/ruby-lang.org/) (>= 3.0)
230
+ * [RDF.rb](https:/rubygems.org/gems/rdf) (~> 3.3), only needed for SPARQL
229
231
  S-expressions
230
232
 
231
233
  # Installation
@@ -252,6 +254,10 @@ as follows:
252
254
  * <https://github.com/dryruby/sxp.rb>
253
255
  * <https://rubygems.org/gems/sxp.rb>
254
256
 
257
+ ## Change Log
258
+
259
+ See [Release Notes on GitHub](https://github.com/dryruby/sxp.rb/releases)
260
+
255
261
  ## Authors
256
262
 
257
263
  * [Arto Bendiken](https://github.com/artob) - <https://ar.to/>
@@ -262,6 +268,7 @@ as follows:
262
268
  * [Ben Lavender](https://github.com/bhuga) - <https://bhuga.net/>
263
269
 
264
270
  ## Contributing
271
+
265
272
  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.
266
273
 
267
274
  * Do your best to adhere to the existing coding conventions and idioms.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.4
1
+ 2.0.0
@@ -56,6 +56,7 @@ end
56
56
  class String
57
57
  ##
58
58
  # Returns the SXP representation of this object. Uses SPARQL-like escaping.
59
+ # Uses any recorded quote style from an originally parsed string.
59
60
  #
60
61
  # @return [String]
61
62
  def to_sxp(**options)
@@ -69,14 +70,29 @@ class String
69
70
  when (0x0C) then '\f'
70
71
  when (0x0D) then '\r'
71
72
  when (0x0E..0x1F) then sprintf("\\u%04X", u.ord)
72
- when (0x22) then '\"'
73
+ when (0x22) then as_dquote? ? '\"' : '"'
74
+ when (0x27) then as_squote? ? "\'" : "'"
73
75
  when (0x5C) then '\\\\'
74
76
  when (0x7F) then sprintf("\\u%04X", u.ord)
75
77
  else u.chr
76
78
  end
77
79
  end
78
- '"' + buffer + '"'
80
+ if as_dquote?
81
+ '"' + buffer + '"'
82
+ else
83
+ "'" + buffer + "'"
84
+ end
79
85
  end
86
+
87
+ # Record quote style used when parsing
88
+ # @return [:dquote, :squote]
89
+ attr_accessor :quote_style
90
+
91
+ # Render string using double quotes
92
+ def as_squote?; quote_style == :squote; end
93
+
94
+ # Render string using single quotes
95
+ def as_dquote?; quote_style != :squote; end
80
96
  end
81
97
 
82
98
  ##
@@ -15,7 +15,7 @@ module SXP; class Reader
15
15
  def read_token
16
16
  case peek_char
17
17
  when ?(, ?) then [:list, read_char]
18
- when ?" then [:atom, read_string] #"
18
+ when ?", ?' then [:atom, read_string] #" or '
19
19
  else super
20
20
  end
21
21
  end
@@ -36,16 +36,18 @@ module SXP; class Reader
36
36
  # @return [String]
37
37
  def read_string
38
38
  buffer = ""
39
- skip_char # '"'
40
- until peek_char == ?" #"
39
+ quote_char = read_char
40
+ until peek_char == quote_char # " or '
41
41
  buffer <<
42
42
  case char = read_char
43
43
  when ?\\ then read_character
44
44
  else char
45
45
  end
46
46
  end
47
- skip_char # '"'
48
- buffer
47
+ skip_char # " or '
48
+
49
+ # Return string, annotating it with the quotation style used
50
+ buffer.tap {|s| s.quote_style = (quote_char == '"' ? :dquote : :squote)}
49
51
  end
50
52
 
51
53
  ##
@@ -115,7 +115,7 @@ module SXP; class Reader
115
115
  # @return [Array]
116
116
  def read_quote
117
117
  skip_char # "'"
118
- [options[:quote] || :quote, read]
118
+ [options[:quote] || :quote, read.tap {|s| s.quote_style = :squote if s.is_a?(String)}]
119
119
  end
120
120
 
121
121
  ##
@@ -94,6 +94,7 @@ module SXP; class Reader
94
94
  def read_token
95
95
  case peek_char
96
96
  when ?" then [:atom, read_rdf_literal] # "
97
+ when ?' then [:atom, read_rdf_literal] # '
97
98
  when ?< then [:atom, read_rdf_uri]
98
99
  else
99
100
  tok = super
@@ -144,6 +145,7 @@ module SXP; class Reader
144
145
  #
145
146
  # @example
146
147
  # "a plain literal"
148
+ # 'another plain literal'
147
149
  # "a literal with a language"@en
148
150
  # "a typed literal"^^<http://example/>
149
151
  # "a typed literal with a PNAME"^^xsd:string
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.2.4
4
+ version: 2.0.0
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: 2023-05-03 00:00:00.000000000 Z
12
+ date: 2023-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '3.2'
20
+ version: '3.3'
21
21
  type: :runtime
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.2'
27
+ version: '3.3'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: matrix
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '1.4'
48
+ version: '1.5'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '1.4'
55
+ version: '1.5'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -133,14 +133,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - ">="
135
135
  - !ruby/object:Gem::Version
136
- version: '2.6'
136
+ version: '3.0'
137
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  requirements:
139
139
  - - ">="
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubygems_version: 3.4.6
143
+ rubygems_version: 3.4.19
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: A pure-Ruby implementation of a universal S-expression parser.