brag cuts literal when it is not instructed to
#8
Closed
opened 8 years ago by v-nys
·
3 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
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:
And the parse tree, when I use a bar:
I figured this might have something to do with the cut also being applied in nested terms, so I rewrote the rule as follows:
But now the comma is included, so I get:
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.Here’s my attempt to make a test case that reproduces the problem:
parser.rkt
test.rkt
Result:
The comma is there. What am I missing?
I whittled down my code until the comma appeared and what I found was that the comma is missing when I use the following lexer, grammar and test:
If I strip away the atom and try to parse
"[g1,g2]"
, then the comma is there.Thanks. I found the problem & fixed it.