Browse Source

feat: lexical tokens for match

match-statements
Garrit Franke 3 years ago
parent
commit
0745172787
  1. 10
      src/lexer/mod.rs
  2. 12
      tests/match_statements.sb

10
src/lexer/mod.rs

@ -104,6 +104,8 @@ pub enum TokenKind {
StarEqual, StarEqual,
/// "/=" /// "/="
SlashEqual, SlashEqual,
/// "=>"
ArrowRight,
/// "(" /// "("
BraceOpen, BraceOpen,
/// ")" /// ")"
@ -145,6 +147,8 @@ pub enum Keyword {
Boolean, Boolean,
Struct, Struct,
New, New,
Match,
Default,
Unknown, Unknown,
} }
@ -244,6 +248,10 @@ impl Cursor<'_> {
self.bump(); self.bump();
Equals Equals
} }
'>' => {
self.bump();
ArrowRight
}
_ => Assign, _ => Assign,
}, },
':' => Colon, ':' => Colon,
@ -368,6 +376,8 @@ impl Cursor<'_> {
c if c == "continue" => Keyword::Continue, c if c == "continue" => Keyword::Continue,
c if c == "struct" => Keyword::Struct, c if c == "struct" => Keyword::Struct,
c if c == "new" => Keyword::New, c if c == "new" => Keyword::New,
c if c == "match" => Keyword::Match,
c if c == "default" => Keyword::Default,
_ => Keyword::Unknown, _ => Keyword::Unknown,
} }
} }

12
tests/match_statements.sb

@ -0,0 +1,12 @@
fn test_basic_match() {
let x = true
match x {
true => assert(true)
false => assert(false)
}
}
fn main() {
test_basic_match()
}
Loading…
Cancel
Save