-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,26 +1,31 @@ | ||||||||||||||||||
use hdx_atom::{atom, Atom}; | ||||||||||||||||||
use hdx_lexer::{Include, Kind, Token}; | ||||||||||||||||||
use hdx_lexer::{Include, Kind}; | ||||||||||||||||||
|
||||||||||||||||||
use crate::{discard, expect, expect_ignore_case, match_ignore_case, parser::Parser, unexpected, Result}; | ||||||||||||||||||
use crate::{discard, expect, expect_ignore_case, parser::Parser, unexpected, Result}; | ||||||||||||||||||
|
||||||||||||||||||
use super::Parse; | ||||||||||||||||||
|
||||||||||||||||||
pub trait Declaration<'a>: Sized + Parse<'a> { | ||||||||||||||||||
type DeclarationValue: DeclarationValue<'a>; | ||||||||||||||||||
|
||||||||||||||||||
fn parse_name(parser: &mut Parser<'a>) -> Result<Atom> { | ||||||||||||||||||
match parser.next().clone() { | ||||||||||||||||||
Token::Ident(atom) => { | ||||||||||||||||||
let token = parser.next(); | ||||||||||||||||||
match token.kind() { | ||||||||||||||||||
Kind::Ident => { | ||||||||||||||||||
expect!(parser.next(), Kind::Colon); | ||||||||||||||||||
Ok(atom.to_ascii_lowercase()) | ||||||||||||||||||
Ok(parser.parse_atom_lower(token)) | ||||||||||||||||||
} | ||||||||||||||||||
token => unexpected!(parser, token), | ||||||||||||||||||
_ => unexpected!(parser, token), | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
fn parse_important(parser: &mut Parser<'a>) -> Result<bool> { | ||||||||||||||||||
if matches!(parser.peek(), Token::Delim('!')) | ||||||||||||||||||
&& match_ignore_case!(parser.peek_n(2), Token::Ident(atom!("important"))) | ||||||||||||||||||
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")) | ||||||||||||||||||
Comment on lines
+23
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you should be able to do something like:
Suggested change
But I think for this to work we'd need to do some work to both the match macros used. |
||||||||||||||||||
{ | ||||||||||||||||||
parser.advance(); | ||||||||||||||||||
expect_ignore_case!(parser.next_with(Include::all()), Kind::Ident, atom!("important")); | ||||||||||||||||||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.