You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think that Peggy allows this. Instead of having to write: Part ( "," Part )* for "one or more Parts separated by a comma", you could write, e.g.: (Part / ",")+ Now, I'm sure you won't be able to use a slash there - you just need something to separate the item(s) from the separator. You'd also be allowed to use (Part / ",")* to mean "zero or more Parts separated by a comma"
Where you see Part, you could, in fact, put any expression at all. Personally, I think it's much clearer what you're expecting to see. The separator is usually something with no semantic meaning - it's just there to make parsing easier - for both the software and the brain.
The text was updated successfully, but these errors were encountered:
The direction I'd like to go with this is something closer to higher order functions / macros.
We could declare a parameterized meta rule like:
Repetition(Part, Separator)
Part ( Separator Part )* ->
$2.unshift($1)
return $2
This way we get an unambiguous resolution to the structure of the repetition and it can be changed based on preference.
It will also help with things like:
InsertSpace
"" ->
return { $loc, token: " " }
--- becomes something like ---
Insert(Token)
"" ->
return { $loc, token: Token } // TODO: figure out what it means to reference the parameterized rule here, fine with a string literal but could get weird with another parsing rule
InsertSpace = Insert("") // TODO: Figure out how to name and assign these parameterizations
If we do end up adding this parameterization feature we could even ship with some default utilities to handle repetition and other common situations.
I think that Peggy allows this. Instead of having to write:
Part ( "," Part )*
for "one or more Parts separated by a comma", you could write, e.g.:(Part / ",")+
Now, I'm sure you won't be able to use a slash there - you just need something to separate the item(s) from the separator. You'd also be allowed to use(Part / ",")*
to mean "zero or more Parts separated by a comma"Where you see Part, you could, in fact, put any expression at all. Personally, I think it's much clearer what you're expecting to see. The separator is usually something with no semantic meaning - it's just there to make parsing easier - for both the software and the brain.
The text was updated successfully, but these errors were encountered: