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

feature: unary prefix/suffix operator support via PrattParser #710

Merged
merged 2 commits into from
Oct 1, 2022

Conversation

tomtau
Copy link
Contributor

@tomtau tomtau commented Sep 20, 2022

Closes #461

based on #344

Co-authored-by: @segeljakt

@tomtau tomtau requested a review from a team September 20, 2022 14:19
@tomtau tomtau requested a review from a team as a code owner September 20, 2022 14:19
@tomtau tomtau requested review from NoahTheDuke and removed request for a team September 20, 2022 14:19
@tomtau
Copy link
Contributor Author

tomtau commented Sep 29, 2022

@pest-parser/maintainers is it ok to merge and release it? It's non-breaking, but not sure if marking PrecClimber deprecated right away is ok

@NoahTheDuke
Copy link
Member

Sorry, been busy. Is there any reason to deprecate the old parser instead of letting it live side by side?

@tomtau
Copy link
Contributor Author

tomtau commented Sep 29, 2022

Sorry, been busy. Is there any reason to deprecate the old parser instead of letting it live side by side?

because it's a duplicate -- PrattParser can do what PrecClimber can do, but is more general (so it can handle more cases, such as unary ops)

@NoahTheDuke
Copy link
Member

If it's purely additive, is there any reason to rename it? Or is the api fundamentally different somehow?

@tomtau
Copy link
Contributor Author

tomtau commented Sep 30, 2022

If it's purely additive, is there any reason to rename it? Or is the api fundamentally different somehow?

The API is different. See e.g. the calculator test: https://github.com/pest-parser/pest/pull/710/files#diff-e2dbd27540c35bdae26743d1b758d99b1186ec63a0be6abc83dfd4ca70c571edR132

@tomtau
Copy link
Contributor Author

tomtau commented Sep 30, 2022

(plus the original PR's comments: #344 (comment) )

Copy link
Member

@NoahTheDuke NoahTheDuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've had a chance to read through the code. I'm glad to see that the changes to Pest internals are minimal. Overall, this is a good PR and I think it should be merged. Two thoughts:

This might be my Clojure background coming out but I think we should make it clear that we're not going to remove PrecClimber in a future version, just marking it as less powerful/useful than PrattParser. It's important that people can trust the code they write today will still work in the future, even across multiple versions.

I also think that the internal method names nud, led, and lbp are quite terse. I have no idea what they stand for, lol. Given that they're only used internally and only in one place, I think they should get more descriptive names, ideally with at least minimal docstrings.

Thanks so much for getting this cleaned up!

@tomtau
Copy link
Contributor Author

tomtau commented Oct 1, 2022

@NoahTheDuke thanks! I extended the deprecation note.
As for the internal methods, I kept them, but added doc strings on them to explain what they stand for. While those terse names are a bit scary, they are ubiquitous in Pratt parser implementations (given that's what the original 1973 paper used).

@tomtau tomtau merged commit 9f7e4f7 into pest-parser:master Oct 1, 2022
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.

make PrecClimber support prefix and postfix operators
2 participants