ebnf 2.2.0 → 2.3.1
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 -5
- data/VERSION +1 -1
- data/bin/ebnf +0 -1
- data/lib/ebnf/base.rb +2 -1
- data/lib/ebnf/ll1/lexer.rb +24 -0
- data/lib/ebnf/rule.rb +13 -5
- metadata +23 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8591cff439890326aadd4187c5ccb7561d6a6f5f3cd3bc213ae6f23f4d689de
|
4
|
+
data.tar.gz: c53fad830e7de8dbf0d0e7aa477989b2130fa6fbee0c054a2a199689a3ebc6f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07f515ffbfaa5de085c9b63bf7e12ef84428a28fc35f727bc0956557c7e4270213eb51104950befec53c97105f992edea848bc30b22b21e07843bca818edbe63
|
7
|
+
data.tar.gz: 3433f6cfb3de5009caf7013ece30f50bec35aeff65d71dbce7235f753d81d7ab88ce09468cd9d9c0759a453ea9535dd5e9a01ee954837b1f318b4524a9658eec
|
data/README.md
CHANGED
@@ -10,8 +10,8 @@
|
|
10
10
|
## Description
|
11
11
|
This is a [Ruby][] implementation of an [EBNF][] and [BNF][] parser and parser generator.
|
12
12
|
|
13
|
-
### [PEG][]/[Packrat][] Parser
|
14
|
-
In the primary mode, it supports a Parsing Expression Grammar ([PEG][]) parser generator. This performs more
|
13
|
+
### [PEG][] / [Packrat][] Parser
|
14
|
+
In the primary mode, it supports a Parsing Expression Grammar ([PEG][]) parser generator. This performs more minimal transformations on the parsed grammar to extract sub-productions, which allows each component of a rule to generate its own parsing event.
|
15
15
|
|
16
16
|
The resulting {EBNF::PEG::Rule} objects then parse each associated rule according to the operator semantics and use a [Packrat][] memoizer to reduce extra work when backtracking.
|
17
17
|
|
@@ -77,13 +77,13 @@ Generate formatted grammar using HTML (requires [Haml][Haml] gem):
|
|
77
77
|
|
78
78
|
The EBNF gem can also parse [ISO/EIC 14977] Grammars (ISOEBNF) to [S-Expressions][S-Expression].
|
79
79
|
|
80
|
-
grammar = EBNF.parse(File.open('./etc/iso-ebnf.isoebnf', format: :isoebnf)
|
80
|
+
grammar = EBNF.parse(File.open('./etc/iso-ebnf.isoebnf'), format: :isoebnf)
|
81
81
|
|
82
82
|
### Parsing an ABNF Grammar
|
83
83
|
|
84
84
|
The EBNF gem can also parse [ABNF] Grammars to [S-Expressions][S-Expression].
|
85
85
|
|
86
|
-
grammar = EBNF.parse(File.open('./etc/abnf.abnf', format: :abnf)
|
86
|
+
grammar = EBNF.parse(File.open('./etc/abnf.abnf'), format: :abnf)
|
87
87
|
|
88
88
|
### Parser Debugging
|
89
89
|
|
@@ -278,7 +278,7 @@ A copy of the [Turtle EBNF][] and derived parser files are included in the repos
|
|
278
278
|
[ABNF]: https://www.rfc-editor.org/rfc/rfc5234
|
279
279
|
[BNF]: https://en.wikipedia.org/wiki/Backus–Naur_form
|
280
280
|
[EBNF]: https://www.w3.org/TR/REC-xml/#sec-notation
|
281
|
-
[EBNF doc]: https://
|
281
|
+
[EBNF doc]: https://dryruby.github.io/ebnf
|
282
282
|
[First/Follow]: https://en.wikipedia.org/wiki/LL_parser#Constructing_an_LL.281.29_parsing_table
|
283
283
|
[ISO/IEC 14977]:https://www.iso.org/standard/26153.html
|
284
284
|
[LL(1)]: https://www.csd.uwo.ca/~moreno//CS447/Lectures/Syntax.html/node14.html
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.1
|
data/bin/ebnf
CHANGED
data/lib/ebnf/base.rb
CHANGED
data/lib/ebnf/ll1/lexer.rb
CHANGED
@@ -38,6 +38,30 @@ module EBNF::LL1
|
|
38
38
|
# @return [Regexp] defines whitespace, including comments, otherwise whitespace must be explicit in terminals
|
39
39
|
attr_reader :whitespace
|
40
40
|
|
41
|
+
##
|
42
|
+
# Returns a copy of the given `input` string with all `\uXXXX` and
|
43
|
+
# `\UXXXXXXXX` Unicode codepoint escape sequences replaced with their
|
44
|
+
# unescaped UTF-8 character counterparts.
|
45
|
+
#
|
46
|
+
# @param [String] string
|
47
|
+
# @return [String]
|
48
|
+
# @see https://www.w3.org/TR/rdf-sparql-query/#codepointEscape
|
49
|
+
def self.unescape_codepoints(string)
|
50
|
+
::EBNF::Unescape.unescape_codepoints(string)
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# Returns a copy of the given `input` string with all string escape
|
55
|
+
# sequences (e.g. `\n` and `\t`) replaced with their unescaped UTF-8
|
56
|
+
# character counterparts.
|
57
|
+
#
|
58
|
+
# @param [String] input
|
59
|
+
# @return [String]
|
60
|
+
# @see https://www.w3.org/TR/rdf-sparql-query/#grammarEscapes
|
61
|
+
def self.unescape_string(input)
|
62
|
+
::EBNF::Unescape.unescape_string(input)
|
63
|
+
end
|
64
|
+
|
41
65
|
##
|
42
66
|
# Tokenizes the given `input` string or stream.
|
43
67
|
#
|
data/lib/ebnf/rule.rb
CHANGED
@@ -206,10 +206,11 @@ module EBNF
|
|
206
206
|
end
|
207
207
|
|
208
208
|
# Return SXP representation of this rule
|
209
|
+
#
|
209
210
|
# @return [String]
|
210
|
-
def to_sxp
|
211
|
+
def to_sxp(**options)
|
211
212
|
require 'sxp' unless defined?(SXP)
|
212
|
-
for_sxp.to_sxp
|
213
|
+
for_sxp.to_sxp(**options)
|
213
214
|
end
|
214
215
|
|
215
216
|
alias_method :to_s, :to_sxp
|
@@ -366,11 +367,11 @@ module EBNF
|
|
366
367
|
def to_regexp
|
367
368
|
case expr.first
|
368
369
|
when :hex
|
369
|
-
Regexp.new(translate_codepoints(expr[1]))
|
370
|
+
Regexp.new(Regexp.escape(translate_codepoints(expr[1])))
|
370
371
|
when :istr
|
371
372
|
/#{expr.last}/ui
|
372
373
|
when :range
|
373
|
-
Regexp.new("[#{translate_codepoints(expr[1])}]")
|
374
|
+
Regexp.new("[#{escape_regexp_character_range(translate_codepoints(expr[1]))}]")
|
374
375
|
else
|
375
376
|
raise "Can't turn #{expr.inspect} into a regexp"
|
376
377
|
end
|
@@ -416,6 +417,7 @@ module EBNF
|
|
416
417
|
# @param [Rule] other
|
417
418
|
# @return [Boolean]
|
418
419
|
def ==(other)
|
420
|
+
other.is_a?(Rule) &&
|
419
421
|
sym == other.sym &&
|
420
422
|
kind == other.kind &&
|
421
423
|
expr == other.expr
|
@@ -768,5 +770,11 @@ module EBNF
|
|
768
770
|
@id_seq += 1
|
769
771
|
["_#{@sym}_#{@id_seq}#{variation}".to_sym, ("#{@id}.#{@id_seq}#{variation}" if @id)]
|
770
772
|
end
|
773
|
+
|
774
|
+
# Escape "[", "]", and "\" in ranges so they don't result in a warning or error
|
775
|
+
# about empty character classes.
|
776
|
+
def escape_regexp_character_range(character_range)
|
777
|
+
character_range.gsub(/([\[\]\\])/) {|char| "\\#{char}"}
|
778
|
+
end
|
771
779
|
end
|
772
|
-
end
|
780
|
+
end
|
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.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-23 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: '1.
|
19
|
+
version: '1.2'
|
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: '1.
|
26
|
+
version: '1.2'
|
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.2'
|
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.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: htmlentities
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,70 +72,70 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
75
|
+
version: '1.7'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1.
|
82
|
+
version: '1.7'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: amazing_print
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '1.
|
89
|
+
version: '1.4'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '1.
|
96
|
+
version: '1.4'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rdf-spec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '3.
|
103
|
+
version: '3.2'
|
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.2'
|
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.2'
|
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.2'
|
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.12'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '1.
|
138
|
+
version: '1.12'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: erubis
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -274,7 +274,11 @@ files:
|
|
274
274
|
homepage: https://github.com/dryruby/ebnf
|
275
275
|
licenses:
|
276
276
|
- Unlicense
|
277
|
-
metadata:
|
277
|
+
metadata:
|
278
|
+
documentation_uri: https://dryruby.github.io/ebnf
|
279
|
+
bug_tracker_uri: https://github.com/dryruby/ebnf/issues
|
280
|
+
homepage_uri: https://github.com/dryruby/ebnf
|
281
|
+
source_code_uri: https://github.com/dryruby/ebnf
|
278
282
|
post_install_message:
|
279
283
|
rdoc_options: []
|
280
284
|
require_paths:
|
@@ -283,14 +287,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
283
287
|
requirements:
|
284
288
|
- - ">="
|
285
289
|
- !ruby/object:Gem::Version
|
286
|
-
version: '2.
|
290
|
+
version: '2.6'
|
287
291
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
288
292
|
requirements:
|
289
293
|
- - ">="
|
290
294
|
- !ruby/object:Gem::Version
|
291
295
|
version: '0'
|
292
296
|
requirements: []
|
293
|
-
rubygems_version: 3.
|
297
|
+
rubygems_version: 3.3.3
|
294
298
|
signing_key:
|
295
299
|
specification_version: 4
|
296
300
|
summary: EBNF parser and parser generator in Ruby.
|