[antlr-interest] gunit syntax for tree walker with a flat list of nodes
Kaleb Pederson
kaleb.pederson at gmail.com
Thu May 13 11:01:23 PDT 2010
Here's a simple gunit test for a portion of my grammar which generates a flat
list of nodes:
objectOption walks objectOption:
<<one:"value">> -> (one "value")
In the above, I purposefully left out the caret (i.e. ^(one "value)) since
it's a flat list of nodes and not a tree. Another option which seems intuitive
is to leave off the parenthesis, like this:
objectOption walks objectOption:
<<one:"value">> -> one "value"
In the first case the parenthesis cause an error
1 failures found:
test2 (objectOption walks objectOption, line17) -
expected: (one \"value\")
actual: one \"value\"
And in the second case I get an exception:
line 17:20 no viable alternative at input 'one'
line 17:24 missing ':' at 'value'
line 0:-1 no viable alternative at input '<EOF>'
java.lang.NullPointerException
at org.antlr.gunit.OutputTest.getExpected(OutputTest.java:65)
at org.antlr.gunit.gUnitExecutor.executeTests(gUnitExecutor.java:245)
...
What is the correct way to match a flat tree?
Thanks.
--
Kaleb Pederson
Blog - http://kalebpederson.com
Twitter - http://twitter.com/kalebpederson
More information about the antlr-interest
mailing list