sxp 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61374894094dfef958193088e14f4ad30c9510fdbd99463c2dc7787332fe7322
4
- data.tar.gz: 95bb2ac7d7019cda158a9acf4f62135b9d194d90da2c536d6c8debaa0b5bd4b6
3
+ metadata.gz: '058a4a32d0bc8f49d4032efeeaa309d563d0309304c2c9baae1dc3bcec9e240b'
4
+ data.tar.gz: 6cf5ed0d766a7fe82bf01c888ed1453f4d4e03b0931963b8989a766c0e1f5959
5
5
  SHA512:
6
- metadata.gz: ff36cf0e38d92c01ec88505c2b43ecb675309fe1ba11be06dc1fbd76ff2b0f2f1ed09df8d2758faa01ad977ff959b7d57aecac1458064d7d50951128e9d4a821
7
- data.tar.gz: bbbc68c4a419fe356939a497db48504cc9bc04a738670b51e55cee4126267c2505379e273471de2b5828e4cf3da3812c985065543a1dd7e41d17873273f89c76
6
+ metadata.gz: 1c9f61f82bbc7627edbdda238876e917149a5e6ca6818435f7f52f066ccb776474af0bd1718fe50ce6092fb6c1f16f1efe3610105561402abb656a46860e359b
7
+ data.tar.gz: bc47c210990f6ec08a0d134329d101e249669c61b6d354e4454cdaf9ecedeec99974c084356b7ba41b3a1c4f48dd3e5ff5c6caa9d1d5a9babea81e485e6f88c2
data/README.md CHANGED
@@ -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>
@@ -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.3.0
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.3.0
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-09-01 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