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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -1
  3. data/VERSION +1 -1
  4. data/lib/ebnf/ll1/parser.rb +13 -12
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e418c3276c9f6252edf2fb8e89b815a95731629
4
- data.tar.gz: 1f9fa2b8690bb7d8e5491a94b0f7f0fcc781af99
3
+ metadata.gz: 1f8401a104bc55119f5021d19a88071889b64f24
4
+ data.tar.gz: 0de399d41cbfed84c393b219e2761208a63e8676
5
5
  SHA512:
6
- metadata.gz: 597dcc0e0f174981fc7d8285238f1b74bec9c0e8b4e3294de792d555af36fac9ae4983e112b31534d42f8a24a05fb250535a5c0594d425c15a662d4e97a93187
7
- data.tar.gz: b1df195a3f03dada05472fb222a8df83236c12de389e8566d914b847f85b1be66dd5b8e3e6efcf5c52420794336b185f8fb4e8af9663be455f34f7a325a0c078
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.3
1
+ 0.3.4
@@ -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
- raise Error.new("Unexpected end of input", :production => cur_prod)
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
- raise Error.new("Expected one of #{@first[cur_prod].inspect}",
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
- raise Error.new("Unexpected",
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
- raise Error.new("Expected #{term.inspect}",
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
- :production => @productions.last)
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
- :production => @productions.last, :token => e.token)
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: #{@lineno}] " if @lineno
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.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-20 00:00:00.000000000 Z
11
+ date: 2013-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sxp