Fix bugs, add propper tests
This commit is contained in:
@@ -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)),
|
||||
|
||||
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user