Closed enjoysmath closed 3 years ago
Hi, for situations like this I wrote the tracing capability of Pegged, see https://github.com/PhilippeSigaud/Pegged/wiki/Grammar-Debugging.
But let me try to parse your input with your grammar manually:
Typed
tries to parse a+b:A
, invokes List
.
List
tries to parse a+b:A
, invokes Template
.Template
tries to parse a+b:A
, invokes TemplatePart
.
TemplatePart
tries to parse a+b:A
, invokes Variable
.Variable
tries to parse a+b:A
, invokes identifier
.
identifier
tries to parse a+b:A
, matches a
. Remaining input: +b:A
TemplatePart
matches a
. Remaining input: +b:A
Template
tries to parse +b:A
, invokes another TemplatePart
.
TemplatePart
tries to parse +b:A
, invokes Variable
.Variable
tries to parse +b:A
, invokes identifier
.
identifier
tries to parse +b:A
, fails.TemplatePart
tries to parse +b:A
, invokes Number
.Number
tries to parse +b:A
, fails.TemplatePart
tries to parse +b:A
, invokes Text
.Text
tries to parse +b:A
. Text
cannot match anything but the empty string because it only contains a negative lookahead, repeated 0 or more times. It succeeds on the empty string. Remaining input: +b:A
.Template
has not advanced the input, gives up on trying another TemplatePart
.List
succeeds with a
. Remaining input: +b:A
.Typed
expects literal ":" after List
, but the remaining input is +b:A
, and fails.I assume you expect "+" to be matched by Text
, and it looks like you just forgot the "match anything parser" .
in
Text < (!(Variable / Number / ":" / ",") . )*
Hope this helps, Bastiaan.
Hi, for situations like this I wrote the tracing capability of Pegged, see https://github.com/PhilippeSigaud/Pegged/wiki/Grammar-Debugging.
But let me try to parse your input with your grammar manually:
Typed
tries to parsea+b:A
, invokesList
.
List
tries to parsea+b:A
, invokesTemplate
.
Template
tries to parsea+b:A
, invokesTemplatePart
.
TemplatePart
tries to parsea+b:A
, invokesVariable
.
Variable
tries to parsea+b:A
, invokesidentifier
.
identifier
tries to parsea+b:A
, matchesa
. Remaining input:+b:A
TemplatePart
matchesa
. Remaining input:+b:A
Template
tries to parse+b:A
, invokes anotherTemplatePart
.
TemplatePart
tries to parse+b:A
, invokesVariable
.
Variable
tries to parse+b:A
, invokesidentifier
.
identifier
tries to parse+b:A
, fails.
TemplatePart
tries to parse+b:A
, invokesNumber
.
Number
tries to parse+b:A
, fails.
TemplatePart
tries to parse+b:A
, invokesText
.
Text
tries to parse+b:A
.Text
cannot match anything but the empty string because it only contains a negative lookahead, repeated 0 or more times. It succeeds on the empty string. Remaining input:+b:A
.
Template
has not advanced the input, gives up on trying anotherTemplatePart
.
List
succeeds witha
. Remaining input:+b:A
.Typed
expects literal ":" afterList
, but the remaining input is+b:A
, and fails.I assume you expect "+" to be matched by
Text
, and it looks like you just forgot the "match anything parser".
inText < (!(Variable / Number / ":" / ",") . )*
Hope this helps, Bastiaan.
@veelo Yes, that fixed it! :)
I've attached the entrie project
abstract_spacecraft.zip
. However there is only two files. The other fileterm.d
simply holds the D data structures that I'm "parsing into". Ideally these structures 1-1 correspond with the constructs of the grammar.Here's
app.d
It really is as simple as can be:The errors I'm getting are:
whenever you enter in something more complex that
a:A
, say:a+b:A
. It will fail on that and I can't figure out why. I've tried playing around with the negative lookahead the!...
part of the grammar, to no avail.Since my grammar shouldn't be more that about 5-10x that size, I will probably end up making a hand-rolled parser with simple rules such as only one colon per line, etc.
Let me know if we can fix this so that I can continue using
pegged
.abstract_spacecraft.zip