dlang-community / Pegged

A Parsing Expression Grammar (PEG) module, using the D programming language.
534 stars 66 forks source link

How do you do "Exp Exp" in a PEG grammar. This is not working... #291

Closed enjoysmath closed 4 years ago

enjoysmath commented 4 years ago
"
TT:
Exp      <- 'Type' / App / Abstr / Dep / Ide
Abstr    < :'%s' Ide Exp
App      <- Exp Exp
Dep      < '(' Ide ':' Exp ')' Exp
Ide      <- identifier
"

So that you don't have to go through the trouble of getting my code to run, I'll just tell you what is happening. Clearly the input: x y (x [space] y) should parse as Exp Exp but it's always going to Ide (the first x) and then ignoring the rest.

enjoysmath commented 4 years ago

Got it to work with some modifications:

mixin(grammar(
"
TT:
Exp      <- 'Type' / App / Abstr / Dep / Ide
Fun      <- Abstr / Dep / Ide
Abstr    <- :'%s' Ide :' ' Exp
App      <- Fun :' ' Exp
Dep      < '(' Ide ':' Exp ')' Exp
Ide      <- identifier
".format(lambda)));

in order to eliminate Left-recursions.