Implement challenge 26 ez katka

This commit is contained in:
2022-08-15 20:21:40 -04:00
parent 1eb76f52b1
commit caf6d35b59
3 changed files with 48 additions and 11 deletions

View File

@@ -40,14 +40,13 @@ fn scan(code: &str, mut ix: usize, mut tokens: Tokens) -> Tokens {
let c: char = code[ix..ix + 1].chars().next().unwrap();
if c.is_ascii_alphanumeric() || SPECIAL_CHARS.contains(&c) {
return scan_identifier(code, ix, tokens);
} else if c == '&' {
tokens.push(Token::Ampersand);
} else if c == '=' {
tokens.push(Token::Equal);
} else if c == ';' {
tokens.push(Token::Semicolon);
} else {
panic!("Unexpected char '{}' at index {}", c, ix);
}
match c {
'&' => tokens.push(Token::Ampersand),
'=' => tokens.push(Token::Equal),
';' => tokens.push(Token::Semicolon),
_ => panic!("Unexpected char '{}' at index {}", c, ix),
}
ix += 1;
scan(code, ix, tokens)