tags:

views:

16

answers:

0

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?