dlang-community / Pegged

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

Unwanted space consumption in rule parameter #308

Open thaven opened 2 years ago

thaven commented 2 years ago

In a grammar I did something like this:

IdentifierCont <~ [a-zA-Z0-9_]+

Word(Lit) <- Lit !IdentifierCont

I use it to parse keywords and assure the keyword does not appear just as the start of an identifier: Word("keyword")

Now it turns out this gets expanded to: Word!(pegged.peg.wrapAround!(Spacing, pegged.peg.literal!"keyword", Spacing)). This is obviously not what I intended.

Putting the call in a <- rule prevents this, but makes things cumbersome when space consumption is wanted around the keyword (which would often be the case). IMO when I explicitly pass a single parser to a parameterized rule, that thing should be passed without addition, no matter the type of rule. Space consumption may happen inside the parameterized rule, if that rule is defined to be space-consuming.