ebnf 2.3.5 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/VERSION +1 -1
- data/etc/abnf.sxp +1 -1
- data/etc/ebnf.html +13 -13
- data/etc/ebnf.ll1.rb +1 -1
- data/etc/ebnf.ll1.sxp +94 -94
- data/etc/ebnf.peg.rb +1 -1
- data/etc/ebnf.peg.sxp +29 -29
- data/etc/ebnf.sxp +18 -18
- data/etc/iso-ebnf.sxp +27 -27
- data/etc/sparql.sxp +195 -195
- data/etc/turtle.ebnf +70 -67
- data/etc/turtle.html +56 -106
- data/etc/turtle.peg.sxp +182 -191
- data/etc/turtle.sxp +64 -70
- data/lib/ebnf/abnf.rb +3 -3
- data/lib/ebnf/base.rb +1 -1
- data/lib/ebnf/isoebnf.rb +1 -1
- data/lib/ebnf/native.rb +3 -2
- data/lib/ebnf/parser.rb +4 -2
- data/lib/ebnf/rule.rb +1 -2
- data/lib/ebnf/unescape.rb +1 -1
- data/lib/ebnf/writer.rb +9 -7
- data/lib/ebnf.rb +2 -0
- metadata +16 -23
- data/etc/sparql.html +0 -1425
- data/etc/sparql.ll1.sxp +0 -7372
- data/etc/sparql.peg.rb +0 -532
- data/etc/sparql.peg.sxp +0 -597
- data/etc/turtle.ll1.rb +0 -1482
- data/etc/turtle.ll1.sxp +0 -425
- data/etc/turtle.peg.rb +0 -182
data/lib/ebnf/native.rb
CHANGED
@@ -33,6 +33,7 @@ module EBNF
|
|
33
33
|
when s = scanner.scan(/\A["']/)
|
34
34
|
# Found a quote, scan until end of matching quote
|
35
35
|
s += scanner.scan_until(/#{scanner.matched}|$/)
|
36
|
+
s.quote_style = scanner.matched == "'" ? :squote : :dquote
|
36
37
|
r += s
|
37
38
|
when s = scanner.scan(%r(^@terminals))
|
38
39
|
#debug("eachRule(@terminals)") { "[#{cur_lineno}] #{s.inspect}" }
|
@@ -287,11 +288,11 @@ module EBNF
|
|
287
288
|
case m = s[0,1]
|
288
289
|
when '"', "'" # STRING1 or STRING2
|
289
290
|
l, s = s[1..-1].split(m.rstrip, 2)
|
290
|
-
[Unescape.
|
291
|
+
[Unescape.unescape(l).tap {|str| str.quote_style = (m == "'" ? :squote : :dquote)}, s]
|
291
292
|
when '[' # RANGE, O_RANGE
|
292
293
|
# Includes RANGE and O_RANGE which can't include a ']'
|
293
294
|
l, s = s[1..-1].split(']', 2)
|
294
|
-
[[:range, Unescape.
|
295
|
+
[[:range, Unescape.unescape(l)], s]
|
295
296
|
when '#' # HEX
|
296
297
|
s.match(/(#x\h+)(.*)$/)
|
297
298
|
l, s = $1, $2
|
data/lib/ebnf/parser.rb
CHANGED
@@ -63,14 +63,16 @@ module EBNF
|
|
63
63
|
#
|
64
64
|
# [16] STRING1 ::= '"' (CHAR - '"')* '"'
|
65
65
|
terminal(:STRING1, STRING1) do |value|
|
66
|
-
|
66
|
+
using ::EBNF
|
67
|
+
value[1..-2].tap {|s| s.quote_style = :dquote}
|
67
68
|
end
|
68
69
|
|
69
70
|
# Match single quote string
|
70
71
|
#
|
71
72
|
# [17] STRING2 ::= "'" (CHAR - "'")* "'"
|
72
73
|
terminal(:STRING2, STRING2) do |value|
|
73
|
-
|
74
|
+
using ::EBNF
|
75
|
+
value[1..-2].tap {|s| s.quote_style = :squote}
|
74
76
|
end
|
75
77
|
|
76
78
|
# The `CHAR` and `R_CHAR` productions are not used explicitly
|
data/lib/ebnf/rule.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'scanf'
|
2
2
|
require 'strscan'
|
3
|
+
require 'sxp' unless defined?(SXP)
|
3
4
|
|
4
5
|
module EBNF
|
5
6
|
# Represent individual parsed rules
|
@@ -158,7 +159,6 @@ module EBNF
|
|
158
159
|
# @return [Rule]
|
159
160
|
def self.from_sxp(sxp)
|
160
161
|
if sxp.is_a?(String)
|
161
|
-
require 'sxp' unless defined?(SXP)
|
162
162
|
sxp = SXP.parse(sxp)
|
163
163
|
end
|
164
164
|
expr = sxp.detect {|e| e.is_a?(Array) && ![:first, :follow, :start].include?(e.first.to_sym)}
|
@@ -209,7 +209,6 @@ module EBNF
|
|
209
209
|
#
|
210
210
|
# @return [String]
|
211
211
|
def to_sxp(**options)
|
212
|
-
require 'sxp' unless defined?(SXP)
|
213
212
|
for_sxp.to_sxp(**options)
|
214
213
|
end
|
215
214
|
|
data/lib/ebnf/unescape.rb
CHANGED
@@ -48,7 +48,7 @@ module EBNF::Unescape
|
|
48
48
|
# @return [String]
|
49
49
|
# @see https://www.w3.org/TR/rdf-sparql-query/#grammarEscapes
|
50
50
|
def unescape_string(input)
|
51
|
-
input.gsub(ECHAR) {
|
51
|
+
input.gsub(ECHAR) {|escaped| ESCAPE_CHARS[escaped] || escaped}
|
52
52
|
end
|
53
53
|
module_function :unescape_string
|
54
54
|
|
data/lib/ebnf/writer.rb
CHANGED
@@ -243,9 +243,9 @@ module EBNF
|
|
243
243
|
# Format each rule, considering the available rhs size
|
244
244
|
rules.each do |rule|
|
245
245
|
buffer = if rule.pass?
|
246
|
-
"\n%-#{lhs_length-2}s " %
|
246
|
+
"\n%-#{lhs_length-2}s " % '@pass'
|
247
247
|
elsif rule.kind == :terminals
|
248
|
-
"\n%-#{lhs_length-2}s" %
|
248
|
+
"\n%-#{lhs_length-2}s" % '@terminals'
|
249
249
|
else
|
250
250
|
lhs_fmt % {id: "[#{rule.id}]", sym: rule.sym}
|
251
251
|
end
|
@@ -285,7 +285,7 @@ module EBNF
|
|
285
285
|
if expr.is_a?(String)
|
286
286
|
return expr.length == 1 ?
|
287
287
|
format_ebnf_char(expr) :
|
288
|
-
format_ebnf_string(expr
|
288
|
+
format_ebnf_string(expr)
|
289
289
|
end
|
290
290
|
parts = {
|
291
291
|
alt: (@options[:html] ? %(<code class="grammar-alt">|</code> ) : "| "),
|
@@ -354,11 +354,12 @@ module EBNF
|
|
354
354
|
|
355
355
|
# Format a single-character string, prefering hex for non-main ASCII
|
356
356
|
def format_ebnf_char(c)
|
357
|
+
quote = c.as_dquote? ? '"' : "'"
|
357
358
|
case c.ord
|
358
|
-
when
|
359
|
+
when 0x21 then (@options[:html] ? %("<code class="grammar-literal">#{@coder.encode c}</code>") : %{"#{c}"})
|
359
360
|
when 0x22 then (@options[:html] ? %('<code class="grammar-literal">"</code>') : %{'"'})
|
360
|
-
when (0x23..0x7e) then (@options[:html] ? %(
|
361
|
-
when (0x80..0xFFFD) then (@options[:html] ? %(
|
361
|
+
when (0x23..0x7e) then (@options[:html] ? %(#{quote}<code class="grammar-literal">#{@coder.encode c}</code>#{quote}) : %{#{quote}#{c}#{quote}})
|
362
|
+
when (0x80..0xFFFD) then (@options[:html] ? %(#{quote}<code class="grammar-literal">#{@coder.encode c}</code>#{quote}) : %{#{quote}#{c}#{quote}})
|
362
363
|
else escape_ebnf_hex(c)
|
363
364
|
end
|
364
365
|
end
|
@@ -384,7 +385,8 @@ module EBNF
|
|
384
385
|
end
|
385
386
|
|
386
387
|
# Escape a string, using as many UTF-8 characters as possible
|
387
|
-
def format_ebnf_string(string
|
388
|
+
def format_ebnf_string(string)
|
389
|
+
quote = string.as_dquote? ? '"' : "'"
|
388
390
|
string.each_char do |c|
|
389
391
|
case c.ord
|
390
392
|
when 0x00..0x19, quote.ord
|
data/lib/ebnf.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ebnf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sxp
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: scanf
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.3'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
54
|
+
version: '3.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: htmlentities
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,48 +100,48 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '3.
|
103
|
+
version: '3.3'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '3.
|
110
|
+
version: '3.3'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rdf-turtle
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '3.
|
117
|
+
version: '3.3'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '3.
|
124
|
+
version: '3.3'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: nokogiri
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '1.
|
131
|
+
version: '1.15'
|
132
132
|
- - ">="
|
133
133
|
- !ruby/object:Gem::Version
|
134
|
-
version: 1.
|
134
|
+
version: 1.15.4
|
135
135
|
type: :development
|
136
136
|
prerelease: false
|
137
137
|
version_requirements: !ruby/object:Gem::Requirement
|
138
138
|
requirements:
|
139
139
|
- - "~>"
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version: '1.
|
141
|
+
version: '1.15'
|
142
142
|
- - ">="
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version: 1.
|
144
|
+
version: 1.15.4
|
145
145
|
- !ruby/object:Gem::Dependency
|
146
146
|
name: erubis
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -242,16 +242,9 @@ files:
|
|
242
242
|
- etc/iso-ebnf.isoebnf
|
243
243
|
- etc/iso-ebnf.sxp
|
244
244
|
- etc/sparql.ebnf
|
245
|
-
- etc/sparql.html
|
246
|
-
- etc/sparql.ll1.sxp
|
247
|
-
- etc/sparql.peg.rb
|
248
|
-
- etc/sparql.peg.sxp
|
249
245
|
- etc/sparql.sxp
|
250
246
|
- etc/turtle.ebnf
|
251
247
|
- etc/turtle.html
|
252
|
-
- etc/turtle.ll1.rb
|
253
|
-
- etc/turtle.ll1.sxp
|
254
|
-
- etc/turtle.peg.rb
|
255
248
|
- etc/turtle.peg.sxp
|
256
249
|
- etc/turtle.sxp
|
257
250
|
- lib/ebnf.rb
|
@@ -293,14 +286,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
293
286
|
requirements:
|
294
287
|
- - ">="
|
295
288
|
- !ruby/object:Gem::Version
|
296
|
-
version: '
|
289
|
+
version: '3.0'
|
297
290
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
298
291
|
requirements:
|
299
292
|
- - ">="
|
300
293
|
- !ruby/object:Gem::Version
|
301
294
|
version: '0'
|
302
295
|
requirements: []
|
303
|
-
rubygems_version: 3.4.
|
296
|
+
rubygems_version: 3.4.19
|
304
297
|
signing_key:
|
305
298
|
specification_version: 4
|
306
299
|
summary: EBNF parser and parser generator in Ruby.
|