diff options
| author | Cody <cody@codyq.dev> | 2022-12-15 14:18:13 -0600 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2022-12-15 14:18:13 -0600 |
| commit | 900bd3d64ac4c5c4c1511ab8388da3f2ed77849f (patch) | |
| tree | 8de3006843d9dc717bf1c00d9942a068c90f413c /src | |
| parent | bddb011df4999f7ffeeddf6a4b66e2da6ab19ea0 (diff) | |
| download | sloth-900bd3d64ac4c5c4c1511ab8388da3f2ed77849f.tar.gz | |
Replace `let` keyword with `val` and `var`
Thanks for pointing out that using `let` and `let mut` was stupid for a
scripting language @mworzala
Diffstat (limited to 'src')
| -rw-r--r-- | src/lexer.rs | 6 | ||||
| -rw-r--r-- | src/main.rs | 6 |
2 files changed, 8 insertions, 4 deletions
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); } } |
