-
Notifications
You must be signed in to change notification settings - Fork 1
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
token definitions #2
Comments
This looks almost the same. In my code I also have owned pub enum TokenValueRef<'a> {
Text(&'a str),
BlockStart,
VarStart,
BlockEnd,
VarEnd,
Name(&'a str),
Value(ConstRef<'a>),
Operator(&'a str),
Punctuation(char),
InterpolationStart,
InterpolationEnd,
CommentStart, // Not in vanilla Twig.
}
impl<'a> Into<TokenValue> for TokenValueRef<'a> {
fn into(self) -> TokenValue {
...
}
}
pub enum TokenValue {
Text(String),
BlockStart,
VarStart,
BlockEnd,
VarEnd,
Name(String),
Value(Const),
Operator(String),
Punctuation(char),
InterpolationStart,
InterpolationEnd,
CommentStart, // Not in vanilla Twig.
} The differences:
|
In my notation everything with an underscore is 'unstable', because I don't need it yet. So _Eof is definetely a candidate for removal. Interpolation is still unimplemented in my parser. Numbers: I suggest
I was thinking about saving numbers redundantly before, i.e. str-slice + parsed value. This way one has to do the conversion once upfront, but saves later conversions. My implementation would currently have to convert back to string at a later stage. Yours would need to parse values later - possibly multiple times. This would be a mix of both our approaches. With Punctuation it might also benefit to store the char representation additionally. But that's probably micro-optimazition not really worth it. |
Will be gone.
Will do that.
Ok. Sadly, no built-in BigInt in Rust.
I very much intended to have another value representation after the lexing, which would closely match the use case, so I don't see issue at this stage. |
Tokens: I like it, that you are only storing references instead of strings. This is something that I tried to, but I postponed it. I think we would need some helper object to support mutability.
I was experimenting with something like this - but I decided it would be way too complex right now to implement a nice + safe interface for it: https://gist.github.com/colin-kiegel/735df3ddb40da853c923.
This is my current definition in
lexer/token/mod.rs
:Var
to ExpressionNumber
to Integer vs. Floating without keeping the stringThe text was updated successfully, but these errors were encountered: