Skip to content
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

Split parser into main entrypoint and two helpers #211

Merged
merged 3 commits into from
Dec 27, 2024

Conversation

neuroevolutus
Copy link
Contributor

parse now calls into parse_expression and is a bit easier to read.

@neuroevolutus neuroevolutus marked this pull request as draft December 26, 2024 08:11
@neuroevolutus neuroevolutus marked this pull request as ready for review December 26, 2024 08:17
@tekknolagi
Copy link
Owner

Ooh, I like that this cleans up the massive function. I wonder about the names. Both functions are parsing expressions and I don't know how name a meaningful difference between the two. The latter feels more cleanly like a parse_binop. I would be interested in hearing your thoughts on this. Maybe parse_unary? parse_atom?

@tekknolagi
Copy link
Owner

Unrelated, I gotta figure out how to turn off preview deploys and building Docker images for others' PRs. Sorry about the red Xes.

@neuroevolutus
Copy link
Contributor Author

Unrelated, I gotta figure out how to turn off preview deploys and building Docker images for others' PRs. Sorry about the red Xes.

No worries!

@neuroevolutus
Copy link
Contributor Author

neuroevolutus commented Dec 26, 2024

Ooh, I like that this cleans up the massive function. I wonder about the names. Both functions are parsing expressions and I don't know how name a meaningful difference between the two. The latter feels more cleanly like a parse_binop. I would be interested in hearing your thoughts on this. Maybe parse_unary? parse_atom?

I think that parse_unary would be a fine name for the new function. parse_binop would also be a great choice for renaming the existing parse function. Alternatively, since parse is responsible for parsing an entire program (as far as I understand), what would you think of renaming it to parse_program?

As a side note, I really appreciate how you have a lot of unit tests in the code. It really does make a world of a difference when trying out small refactors such as this.

@tekknolagi
Copy link
Owner

Let's go with parse_unary and parse_binary and then we can do parse = parse_binary. Alternately, we can make parse an entirely new function that doesn't take a precedence and then make the precedence non-optional for the other two internal functions. I leave this decision up to you; both are fine with me. After these renames, I would be delighted to merge.

@tekknolagi tekknolagi changed the title Add parse_expression function to simplify parser Split parser into main entrypoint and two helpers Dec 27, 2024
The driver function is still named `parse`. It does not accept any
precedence parameter and simply calls into the `parse_binary` helper
function using an initial precedence of 0. `parse_binary` now contains
the logic of the previous `parse` function. The precedence parameters of
`parse_unary` and `parse_binary` are made non-optional.
@tekknolagi tekknolagi merged commit 2af3efd into tekknolagi:trunk Dec 27, 2024
45 of 47 checks passed
@tekknolagi
Copy link
Owner

Thank you!

@tekknolagi tekknolagi deployed to scrapscript-pr-211 December 27, 2024 22:48 — with GitHub Actions Active
@neuroevolutus neuroevolutus deleted the parse-expression branch December 30, 2024 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants