Fix bugs, add propper tests

This commit is contained in:
2026-02-03 13:20:23 +02:00
parent 081ff9a27a
commit 4b61adea5d
58 changed files with 1103 additions and 285 deletions

View File

@@ -30,6 +30,12 @@ impl Token {
pub fn tt(&self) -> &TokenType {
&self.tt
}
pub fn new_test(tt: TokenType) -> Self {
Self {
loc: Loc::default(),
tt
}
}
}
@@ -81,6 +87,9 @@ pub fn tokenise(s: &str, file_p: &str) -> anyhow::Result<Vec<Token>> {
buf.push(*c);
last = *c;
}
let buf = buf
.replace("\\n", "\n")
.replace("\\r", "\r");
tokens.push(Token::new(TokenType::string(&buf, false), &loc));
}
'\'' => {
@@ -251,6 +260,7 @@ lazy_static::lazy_static!(
("return", TokenType::Keyword(Keyword::Return)),
("loop", TokenType::Keyword(Keyword::Loop)),
("as", TokenType::Keyword(Keyword::As)),
("self", TokenType::Keyword(Keyword::Self_)),
("{", TokenType::Delim(Delimiter::CurlyL)),
("}", TokenType::Delim(Delimiter::CurlyR)),
("[", TokenType::Delim(Delimiter::SquareL)),

View File

@@ -16,6 +16,9 @@ impl Ident {
pub fn as_path(self) -> Path {
Path(vec![self])
}
pub fn new(s: impl ToString) -> Self {
Self(s.to_string())
}
}
@@ -71,7 +74,7 @@ pub enum Keyword {
Type, While, For, Break, Continue,
Let, Const, Mut, Static,
True, False, Include, Extern, Return,
As, Loop
As, Loop, Self_
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]