Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Added support for pratt parsers with up to 676 operators#682

Closed
TheOnlyTails wants to merge 8 commits into
zesterer:mainfrom
TheOnlyTails:bigger_pratt
Closed

Added support for pratt parsers with up to 676 operators#682
TheOnlyTails wants to merge 8 commits into
zesterer:mainfrom
TheOnlyTails:bigger_pratt

Conversation

@TheOnlyTails
Copy link
Copy Markdown

@TheOnlyTails TheOnlyTails commented Oct 20, 2024

Adds support for 676-operator pratt parsers (AA..=ZZ)
(this took exactly 5 minutes using multi-cursors)

Closes #658

@zesterer
Copy link
Copy Markdown
Owner

Hmm, I think this is likely to have a non-trivial impact on compilation time. Remember that the macro system still needs to generate all of those impls and the type system needs to check them, even if they go unused.

I'm happy to see the number of operators supported by pratt increased a little: let's say, to 64. But I think this is excessive.

@TheOnlyTails
Copy link
Copy Markdown
Author

Agreed, I tested it out and it crashed my editor when running clippy, not to mention having to increase the recursion limit for macro expansion.

@wackbyte
Copy link
Copy Markdown
Contributor

Maybe it could be supported with nested tuples? but that might be too hacky

@zesterer
Copy link
Copy Markdown
Owner

It might be a possibility, yes.

@TheOnlyTails
Copy link
Copy Markdown
Author

I'll see if I can make that a reality.

Comment thread src/pratt.rs
);

#[allow(unused_variables, non_snake_case)]
impl<'a, Atom, T, const N: usize> Pratt<Atom, [T; N]> {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't think this is doing what you think it's doing, unfortunately. This requires that all operators are of exactly the same time, which is almost useless. For this to be useful you'd need to implement Operator for Box<dyn Operator>, but then the code below like T::IS_PREFIX and others would need to change to check what kind of operator it is at run time.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah, that sucks. I tried looking at the choice combinator to use the same tuple nesting logic, but unfortunately macro syntax still flies over my head.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yeah, there's a good reason I bounced off this problem the first time round. Maybe I'll give it another go soon.

@zesterer
Copy link
Copy Markdown
Owner

Closing this since #685 added support for nested pratt operators.

@zesterer zesterer closed this Oct 25, 2024
@TheOnlyTails TheOnlyTails deleted the bigger_pratt branch October 25, 2024 23:40
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.

Pratt parser only implemented for tuples A..Z

3 participants