Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Simplified API for parsing arbitrary _nt_ productions #9

wants to merge 1 commit into from

3 participants


A simple modification in one line gives parse a root option. With it one can simply type

  def setup ; @parser = ; end
  result = @parser.parse text, root: :function

instead of

  @parser.root = "function"
  result = @parser.parse text
  @parser.root = "program"

The existing/old interface is unchanged, so no code breaks.


I too would like to see this nicety included, particularly for writing tests.


Sorry it took time to incorporate - you provided no test and hadn't done the equivalent thing with consume_all_input. The latest GH version and gem contain both these, with tests.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 4, 2010
  1. @mjk-at-sag
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/treetop/runtime/compiled_parser.rb
2  lib/treetop/runtime/compiled_parser.rb
@@ -15,7 +15,7 @@ def initialize
def parse(input, options = {})
@index = options[:index] if options[:index]
- result = send("_nt_#{root}")
+ result = send("_nt_#{options[:root] || root}")
return nil if (consume_all_input? && index != input.size)
return, index...(index + 1)) if result == true
return result
Something went wrong with that request. Please try again.