Hi,
I'm currently writing a grammar for a Prolog-like language. It contains the following rule: abstract-list : /"[" [abstract-term ("," abstract-term)* ["|" (abstract-list | abstract-variable)]] /"]"
If I use this rule to parse a larger data structure which contains an abstract list (for instance, (mycompound([g1,g2]))
), the comma disappears from the parsed datum. If I put in a vertical bar instead, that is included in the parsed datum.
So, the whole parse tree, when I use a comma:
(at
(treelabel
((abstract-atom "mycompound" (abstract-list (abstract-g-variable 1) (abstract-g-variable 2))))))
And the parse tree, when I use a bar:
(at
(treelabel
((abstract-atom "mycompound" (abstract-list (abstract-g-variable 1) "|" (abstract-g-variable 2))))))
I figured this might have something to do with the cut also being applied in nested terms, so I rewrote the rule as follows:
abstract-list : /"[" [abstract-term term-tail ["|" (abstract-list | abstract-variable)]] /"]"
@term-tail : ("," abstract-term)*
But now the comma is included, so I get:
(at
(treelabel
((abstract-atom "mycompound" (abstract-list (abstract-g-variable 1) "," (abstract-g-variable 2))))))
The latter is the result I want, but fail to see why the original rule and the one with the term-tail
spliced in lead to a different outcome.