gunit syntax for tree walker with a flat list of nodes
Posted
by Kaleb Pederson
on Stack Overflow
See other posts from Stack Overflow
or by Kaleb Pederson
Published on 2010-05-14T17:00:53Z
Indexed on
2010/05/14
17:04 UTC
Read the original article
Hit count: 638
Here's a simple gunit test for a portion of my tree grammar which generates a flat list of nodes:
objectOption walks objectOption:
<<one:"value">> -> (one "value")
Although you define a tree in ANTLR's rewrite syntax using a caret (i.e. ^(ROOT child...)
), gunit matches trees without the caret, so the above represents a tree and it's not surprising that it fails: it's a flat list of nodes and not a tree. This results in a test failure:
1 failures found:
test2 (objectOption walks objectOption, line17) -
expected: (one \"value\")
actual: one \"value\"
Another option which seems intuitive is to leave off the parenthesis, like this:
objectOption walks objectOption:
<<one:"value">> -> one "value"
But gunit
doesn't like this syntax. It seems to result in a parse failure in the gunit grammar:
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?
© Stack Overflow or respective owner