Skip to content

implement a string -> PackedTree parser #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 27, 2024
Merged

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Nov 25, 2024

Summary

Add a parser for PackedTrees that operates directly on S-expression
strings, without going through an intermediate SexpNode tree.

Details

  • move the existing fromSexp procedure from trees to tree_parser

  • add the parseSexp and fromSexp procedures to tree_parser, both
    which take a string as the parameter. The parser reuses the
    existing lexer/parser provided by SexpParser

  • change the generic fromSexp interface procedure to take a typed
    value and Literals object as input, instead of a SexpNode and
    PackedTree, making them more generally applicable

  • update the fromSexp usages in phy.nim; first parsing an S-
    expression into a SexpNode. This should speed up a parsing a little


Notes For Reviewers

  • the parser deliberately doesn't recurse into itself, so that arbitrarily nested trees can be parsed without causing a stack overflow

In addition to moving the procedures, the generic interface (`fromSexp`
and `fromSexpSym`) is changed such that no `SexpNode` or `PackedTree`
is passed along to the procedures. This makes the interface more
flexible, allowing it to be used in a context where no `SexpNode` or
tree is available.
Parsing a string into an `SexpNode` tree first and then parsing said
`SexpNode` tree into a `PackedTree` is unnecessarily wasteful. It's
much more efficient to parse the string directly into a node sequence.

The new parser is based on the existing `SexpParser`. It also doesn't
use recursion, allowing it to parse arbitrarily nested S-expressions
without causing a stack overflow.
The `phy` program can now parse the strings directly into a
`PackedTree`, without needing an intermediate `SexpNode` parsing step.
This should speed parsing up a bit.
@zerbina zerbina added the enhancement New feature or request label Nov 25, 2024
@zerbina zerbina changed the title implement a implement a string -> PackedTree parser Nov 25, 2024
@saem saem merged commit e1138ec into nim-works:main Nov 27, 2024
5 checks passed
@zerbina zerbina deleted the tree-parser branch November 27, 2024 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants