I'm trying to create an AST using ANTLR tree grammar.
Given a syntax like following:
rule : head ':-' litlist (';' ':-' litlist)* DOT_END
I want to create a tree like following
^(RULES ^(head litlist)+)
That is, I want (head litlist)
to be repeated as many as the number of litlist
in the syntax. I tried something like above, but I'm getting an error like this:
Syntax error:required (...)+ loop did not match anything at input EXPR where EXPR is another term in the grammar.
Basically I want something like following:
a : type ID (',' ID)* ';' -> ^(type ID)+;
which is described in Tree constructon.
But my syntax has multiple tokens inside repeated clause, which seems to be a problem.
What is the right way to do this?