Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Simplified API for parsing arbitrary _nt_ productions #9

Closed
wants to merge 1 commit into from

3 participants

@mjk-at-sag

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

  def setup ; @parser = LambdaCalculus.new ; 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.

@anibali

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

@cjheath
Collaborator

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
View
2  lib/treetop/runtime/compiled_parser.rb
@@ -15,7 +15,7 @@ def initialize
def parse(input, options = {})
prepare_to_parse(input)
@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 SyntaxNode.new(input, index...(index + 1)) if result == true
return result
Something went wrong with that request. Please try again.