ebnf 0.3.3 → 0.3.4
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 +4 -4
- data/README.md +6 -1
- data/VERSION +1 -1
- data/lib/ebnf/ll1/parser.rb +13 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f8401a104bc55119f5021d19a88071889b64f24
|
4
|
+
data.tar.gz: 0de399d41cbfed84c393b219e2761208a63e8676
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c35b089907a7e56b30992d18447ef3fc3f3d145c289d0853d68611f350170120bf48f8b3553bb3e754f53568c11e1dbce96cb561ae6fa165f5a66521e4a4214
|
7
|
+
data.tar.gz: 749257622576d3c09da9dd4eb45463e9838b149fb57f97e5fd24e31adf83d75c42e6410c8b0292619c0e4009300594fa0ce4264351f5a882c649f907b4d31f00
|
data/README.md
CHANGED
@@ -102,14 +102,16 @@ and [First Follow Notation-3 rules](http://www.w3.org/2000/10/swap/grammar/first
|
|
102
102
|
Full documentation available on [Rubydoc.info][EBNF doc].
|
103
103
|
|
104
104
|
## Future Work
|
105
|
-
* Detect FIRST/FOLLOW and left-recursion conflicts.
|
106
105
|
* Generate HTML output of parser results.
|
107
106
|
* Better LL(1) parser tests
|
107
|
+
* Either generate [Packrat parser][Packrat] for a [Parsing Regular Expression Grammar][PEG], or integrate with [Treetop][] or similar.
|
108
108
|
|
109
109
|
## Author
|
110
110
|
* [Gregg Kellogg](http://github.com/gkellogg) - <http://greggkellogg.net/>
|
111
111
|
|
112
112
|
## Contributing
|
113
|
+
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.
|
114
|
+
|
113
115
|
* Do your best to adhere to the existing coding conventions and idioms.
|
114
116
|
* Don't use hard tabs, and don't leave trailing whitespace on any line.
|
115
117
|
* Do document every method you add using [YARD][] annotations. Read the
|
@@ -139,3 +141,6 @@ A copy of the [Turtle EBNF][] and derived parser files are included in the repos
|
|
139
141
|
[LL(1) Parser]: http://en.wikipedia.org/wiki/LL_parser
|
140
142
|
[Tokenizer]: http://en.wikipedia.org/wiki/Lexical_analysis#Tokenizer
|
141
143
|
[Turtle EBNF]: http://dvcs.w3.org/hg/rdf/file/default/rdf-turtle/turtle.bnf
|
144
|
+
[Packrat]: http://pdos.csail.mit.edu/~baford/packrat/thesis/
|
145
|
+
[PEG]: http://en.wikipedia.org/wiki/Parsing_expression_grammar
|
146
|
+
[Treetop]: http://rubygems.org/gems/treetop
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
data/lib/ebnf/ll1/parser.rb
CHANGED
@@ -274,15 +274,14 @@ module EBNF::LL1
|
|
274
274
|
|
275
275
|
if token.nil?
|
276
276
|
if !(first_include?(cur_prod, :_eps) && follow_include?(cur_prod, :_eof))
|
277
|
-
# End of file, and production does not contain eps, or it does, but follow does not contain eof
|
278
|
-
|
277
|
+
# End of file, and production does not contain eps, or it does, but follow does not contain eof
|
278
|
+
error("parse(production)", "Unexpected end of input", lineno: lineno, production: cur_prod, raise: true)
|
279
279
|
else
|
280
280
|
debug("parse(production)") {"End of input prod #{cur_prod.inspect}"}
|
281
281
|
end
|
282
282
|
elsif prod_branch = @branch[cur_prod]
|
283
283
|
sequence = prod_branch.fetch(token.representation) do
|
284
|
-
|
285
|
-
:token => token, :production => cur_prod)
|
284
|
+
error("parse(production)", "Expected one of #{@first[cur_prod].inspect}", token: token, production: cur_prod, raise: true)
|
286
285
|
end
|
287
286
|
debug("parse(production)") do
|
288
287
|
"token #{token.representation.inspect} " +
|
@@ -292,8 +291,7 @@ module EBNF::LL1
|
|
292
291
|
end
|
293
292
|
todo_stack.last[:terms] += sequence
|
294
293
|
else
|
295
|
-
|
296
|
-
:production => cur_prod, :token => token)
|
294
|
+
error("parse(production)", "Unexpected", token: token, production: cur_prod, raise: true)
|
297
295
|
end
|
298
296
|
end
|
299
297
|
|
@@ -309,8 +307,7 @@ module EBNF::LL1
|
|
309
307
|
elsif terminals.include?(term)
|
310
308
|
# If term is a terminal, then it is an error if token does not
|
311
309
|
# match it
|
312
|
-
|
313
|
-
:token => get_token, :production => cur_prod)
|
310
|
+
error("parse(token)", "Expected #{term.inspect}", token: get_token, production: cur_prod, raise: true)
|
314
311
|
else
|
315
312
|
token = get_token
|
316
313
|
|
@@ -340,12 +337,12 @@ module EBNF::LL1
|
|
340
337
|
# Skip to the next valid terminal
|
341
338
|
@lexer.recover
|
342
339
|
error("parse(#{e.class})", "With input '#{e.input}': #{e.message}",
|
343
|
-
:
|
340
|
+
production: @productions.last, token: e.token)
|
344
341
|
else
|
345
342
|
# Otherwise, the terminal is fine, just not for this production.
|
346
343
|
@lexer.shift
|
347
344
|
error("parse(#{e.class})", "#{e.message}",
|
348
|
-
:
|
345
|
+
production: @productions.last, token: e.token)
|
349
346
|
end
|
350
347
|
|
351
348
|
# Get the list of follows for this sequence, this production and the stacked productions.
|
@@ -468,14 +465,18 @@ module EBNF::LL1
|
|
468
465
|
# @option options [Token] :token
|
469
466
|
# @see {#debug}
|
470
467
|
def error(node, message, options = {})
|
468
|
+
lineno = @lineno || (options[:token].lineno if options[:token].respond_to?(:lineno))
|
471
469
|
m = "ERROR "
|
472
|
-
m += "[line: #{
|
470
|
+
m += "[line: #{lineno}] " if lineno
|
473
471
|
m += message
|
474
472
|
m += " (found #{options[:token].inspect})" if options[:token]
|
475
473
|
m += ", production = #{options[:production].inspect}" if options[:production]
|
476
474
|
@error_log << m unless @recovering
|
477
475
|
@recovering = true
|
478
476
|
debug(node, m, options.merge(:level => 0))
|
477
|
+
if options[:raise] || @options[:validate]
|
478
|
+
raise Error.new(m, lineno: lineno, token: options[:token], production: options[:production])
|
479
|
+
end
|
479
480
|
end
|
480
481
|
|
481
482
|
##
|
@@ -673,7 +674,7 @@ module EBNF::LL1
|
|
673
674
|
if recover
|
674
675
|
# Recover from lexer error so that we can not bail out too early
|
675
676
|
@lexer.recover
|
676
|
-
error("get_token", "With input '#{e.input}': #{e.message}}")
|
677
|
+
error("get_token", "With input '#{e.input}': #{e.message}}", token: e.token, lineno: e.lineno)
|
677
678
|
retry
|
678
679
|
end
|
679
680
|
raise
|
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: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sxp
|