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

fix more compile errors in parsing token kind #37

Merged

Conversation

koddsson
Copy link

I messed around some more. Not 100% sure this is the correct way to do this still.

expect!(parser.next(), Kind::Colon);
Ok(atom.to_ascii_lowercase())
Ok(parser.parse_atom_lower(token))
Copy link
Author

Choose a reason for hiding this comment

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

Is this the correct way to get a atom from a token ident now?

Copy link
Owner

Choose a reason for hiding this comment

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

Yep! The new Lexer avoids emitting or assigning Atoms until you explicitly call something like parse_atom()/parse_atom_lower(). This lets us skip a bunch of work+memory allocations.

Comment on lines +23 to +28
let peeked = parser.peek();
let nexted_peek = parser.peek_n(2);
if matches!(peeked.kind(), Kind::Delim)
&& matches!(peeked.char(), Some('!'))
&& matches!(nexted_peek.kind(), Kind::Ident)
&& matches!(parser.parse_atom_lower(*nexted_peek), atom!("important"))
Copy link
Author

Choose a reason for hiding this comment

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

Is this ok? Should this have a macro or is there a better way?

Copy link
Owner

Choose a reason for hiding this comment

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

So you should be able to do something like:

Suggested change
let peeked = parser.peek();
let nexted_peek = parser.peek_n(2);
if matches!(peeked.kind(), Kind::Delim)
&& matches!(peeked.char(), Some('!'))
&& matches!(nexted_peek.kind(), Kind::Ident)
&& matches!(parser.parse_atom_lower(*nexted_peek), atom!("important"))
if match_delim!(parser.peek(), Kind::Delim('!'))
&& match_ignore_case!(parser.peek_n(2), Kind::Ident(atom!("important"))

But I think for this to work we'd need to do some work to both the match macros used.

Copy link
Owner

@keithamus keithamus left a comment

Choose a reason for hiding this comment

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

This looks good! I'm going to merge this and follow up with some refinement.

@keithamus keithamus merged commit 0d0fae9 into keithamus:rewrite-lexer Jul 28, 2024
1 of 3 checks passed
@koddsson koddsson deleted the more-matches-on-token-kind branch July 29, 2024 07:03
keithamus pushed a commit that referenced this pull request Jul 29, 2024
I messed around some more. Not 100% sure this is the correct way to do
this still.
keithamus pushed a commit that referenced this pull request Oct 23, 2024
I messed around some more. Not 100% sure this is the correct way to do
this still.
keithamus pushed a commit that referenced this pull request Oct 27, 2024
I messed around some more. Not 100% sure this is the correct way to do
this still.
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