From 900bd3d64ac4c5c4c1511ab8388da3f2ed77849f Mon Sep 17 00:00:00 2001 From: Cody Date: Thu, 15 Dec 2022 14:18:13 -0600 Subject: Replace `let` keyword with `val` and `var` Thanks for pointing out that using `let` and `let mut` was stupid for a scripting language @mworzala --- src/lexer.rs | 6 ++++-- src/main.rs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lexer.rs b/src/lexer.rs index 602b5e1..e850cb0 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -49,7 +49,8 @@ pub enum TokenType { Identifier(String), // Keywords - Let, + Val, + Var, Fn, If, @@ -245,7 +246,8 @@ impl<'a> Iterator for Lexer<'a> { } match value.as_str() { - "let" => TokenType::Let, + "val" => TokenType::Val, + "var" => TokenType::Var, "fn" => TokenType::Fn, "if" => TokenType::If, "else" => TokenType::Else, diff --git a/src/main.rs b/src/main.rs index 65e6ee9..5334746 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,9 @@ use lexer::Lexer; const SOURCE: &str = r#" -if 5 >= 7 { +val variable = 5; + +if variable >= 7 { print "Hello World"; } @@ -21,6 +23,6 @@ if 5 >= 7 { fn main() { let lexer = Lexer::new(SOURCE); for token in lexer { - print!("{} ", token.lexeme); + print!("({}) ", token.lexeme); } } -- cgit v1.2.3