Closed AtkinsSJ closed 5 months ago
The FOAM framework's combinator parser uses a concept called "actions"; an action is a function that's named after a symbol in the grammar, and it transforms the result of that symbol (the current return value of symbol(<symbol's name>)
) before it gets returned.
In the face of the issues you're describing, this approach seems to solve everything. There's one little thing about it I didn't like though; these transformations coupled with the grammar, making it difficult for example to choose between outputs such as: AST, high-level AST ("abstract logic tree"), CST. If we can implement these in a way where actions are de-coupled from the grammar I think that might be really flexible.
Regarding $discard
, I there are two options: Sequence, Repeat, etc all need to check for it; vs parsers always return arrays (and an abstract layer removes items with $discard)
Merging now so it doesn't get lost - merging into monorepo-prep-2
Current status:
Questions:
Parser.result()
seems like a good place, but every combinator receives the return value. Do all of them have to handle discarding?a.discard()
is ugly, is there a nicer way?