wip:
Add type system and refator for having only epression
This commit is contained in:
+29
-1
@@ -16,7 +16,7 @@ pub struct Lexer {
|
||||
fn get_keyword_token(word: &str) -> Option<TokenType> {
|
||||
match word {
|
||||
"and" => Some(TokenType::And),
|
||||
"class" => Some(TokenType::Class),
|
||||
"struct" => Some(TokenType::Struct),
|
||||
"do" => Some(TokenType::StartBlock),
|
||||
"end" => Some(TokenType::EndBlock),
|
||||
"false" => Some(TokenType::False),
|
||||
@@ -514,4 +514,32 @@ mod tests {
|
||||
assert_eq!(tokens[1].source_slice.start_position.line, 1);
|
||||
assert_eq!(tokens[1].source_slice.start_position.column, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handle_struct() {
|
||||
let tokens = lex("Cosa :: struct {field1: Number, field2: String}");
|
||||
let tokens_tyepe: Vec<TokenType> = tokens.iter().map(|x| x.token_type.clone()).collect();
|
||||
let tokent_for_check = vec![
|
||||
TokenType::Identifier,
|
||||
TokenType::Colon,
|
||||
TokenType::Colon,
|
||||
TokenType::Struct,
|
||||
TokenType::LeftBrace,
|
||||
TokenType::Identifier,
|
||||
TokenType::Colon,
|
||||
TokenType::Identifier,
|
||||
TokenType::Comma,
|
||||
TokenType::Identifier,
|
||||
TokenType::Colon,
|
||||
TokenType::Identifier,
|
||||
TokenType::RightBrace,
|
||||
TokenType::Eof,
|
||||
];
|
||||
assert_eq!(tokens_tyepe, tokent_for_check);
|
||||
assert_eq!(tokens[0].lexeme, "Cosa");
|
||||
assert_eq!(tokens[5].lexeme, "field1");
|
||||
assert_eq!(tokens[7].lexeme, "Number");
|
||||
assert_eq!(tokens[9].lexeme, "field2");
|
||||
assert_eq!(tokens[11].lexeme, "String");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user