This commit is contained in:
2026-04-11 15:21:03 -04:00
parent 229b026573
commit 2582e8c87e
15 changed files with 301 additions and 199 deletions
+10 -7
View File
@@ -3,6 +3,8 @@ use std::{iter::Peekable, str::CharIndices};
def_tokens! {
symbol {
Dot: ".",
Comma: ",",
Equal: "=",
Colon: ":",
Semicolon: ";",
@@ -23,9 +25,9 @@ def_tokens! {
AsteriskEqual: "*=",
SlashEqual: "/=",
DoubleColon: "::",
Hash: "#",
}
keyword {
Let: "let",
Fn: "fn",
If: "if",
Loop: "loop",
@@ -80,12 +82,15 @@ impl Iterator for Tokens<'_> {
};
}
let inner = match c {
'.' => Token::Dot,
',' => Token::Comma,
'(' => Token::OpenParen,
')' => Token::CloseParen,
'[' => Token::OpenSquare,
']' => Token::CloseSquare,
'{' => Token::OpenCurly,
'}' => Token::CloseCurly,
'#' => Token::Hash,
'+' => then! {
_ => Token::Plus,
'=' => Token::PlusEqual,
@@ -124,15 +129,13 @@ impl Iterator for Tokens<'_> {
Lit::Number(s).into()
}
'"' => {
let mut s = c.to_string();
while let Some((i, c)) = self.chars.peek()
let mut s = String::new();
while let Some((i, c)) = self.chars.next()
&& !matches!(c, '"')
{
s.push(*c);
span.end = *i;
self.chars.next();
s.push(c);
span.end = i;
}
self.chars.next();
Lit::String(s).into()
}
_ => {