Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

WIP: New parser #67

Merged
merged 3 commits into from
Apr 12, 2024
Merged

Conversation

AtkinsSJ
Copy link
Contributor

Current status:

  • Output is overly nested and verbose
  • $discard results are not discarded

Questions:

  • How do we discard results? Parser.result() seems like a good place, but every combinator receives the return value. Do all of them have to handle discarding?
  • Wrapping things in a.discard() is ugly, is there a nicer way?
  • How to take the verbose output and make it clean? Probably a case of modifying each combinator to consider what its contents are.
  • How do we then take the parsed tree and convert its contents into the objects we want? Define a function for each symbol that modifies its output?

@KernelDeimos
Copy link
Collaborator

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)

Current status:
- Output is overly nested and verbose
- $discard results are not discarded

Questions:
- How do we discard results? `Parser.result()` seems like a good place,
  but every combinator receives the return value. Do all of them have
  to handle discarding?
- Wrapping things in `a.discard()` is ugly, is there a nicer way?
- How to take the verbose output and make it clean? Probably a case of
  modifying each combinator to consider what its contents are.
- How do we then take the parsed tree and convert its contents into the
  objects we want? Define a function for each symbol that modifies its
  output?
Actions are run on the output from the grammar-parser of the same name.

JSON parser is finally getting somewhere!
@KernelDeimos
Copy link
Collaborator

Merging now so it doesn't get lost - merging into monorepo-prep-2

@KernelDeimos KernelDeimos marked this pull request as ready for review April 12, 2024 21:37
@KernelDeimos KernelDeimos changed the base branch from trunk to monorepo-prep-2 April 12, 2024 21:37
@KernelDeimos KernelDeimos merged commit df36f1c into HeyPuter:monorepo-prep-2 Apr 12, 2024
3 checks passed
@AtkinsSJ AtkinsSJ deleted the new-parser branch April 13, 2024 13:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants