From: Tom Aadland Date: 2008-07-14T10:00:30+09:00 Subject: Re: Treetop positive lookahead problem Clifford Heath wrote: > Tom Aadland wrote: >> >> This should as I understand it parse the string "foobar" and return only >> "foo". For some reason this returns nil. I tried the opposite (switched >> '&' with '!') and that works like a charm. > > Tom, > > For us to know why, you should post the entire grammar, together with > the text you're parsing, and preferably also a snippet showing how > you're calling the parser. Hi Clifford, Thank you for responding and I'm sorry I didn't provide more information. Also as I said I think I was missing something fundamental. I was gonna paste this in pastie, but pastie is down :( I thought that the 'foo' &'bar' rule meant that bar has to come togehter with foo as in foobar and on top of that not really consume bar so that the text_value returned would only be foo. However the following test below runs fine with that in mind :) What I want with this rule is: match foobar or even foobarsomething, but return the textvalue without bar. grammar FooGrammar rule test_with_bar 'foo' (&'bar' .+) { def value text_value end } end end require 'rubygems' require 'treetop' require 'test/unit' class TestFoo < Test::Unit::TestCase Treetop.load "foo_grammar" def test_parse_foo_with_bar res = FooGrammarParser.new.parse("foobar") assert_equal res.value, "foobar" end end Thanks, Tom -- Posted via http://www.ruby-forum.com/.