Skip to content

Commit 80ac8a8

Browse files
committed
feat: better lexer
1 parent be3a6e6 commit 80ac8a8

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

stack-control/src/compiletime/lexer.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,14 @@ pub fn split_to_tokens<'a>(mut symbols: Peekable<impl Iterator<Item = char> + Cl
7777

7878
// Or whitespace
7979
.or_else(|| {
80-
if symbols.peek()?.is_whitespace() {return Some(Token::WhiteSpace(symbols.next()?))}
80+
if symbols.peek()?.is_whitespace() { return Some(Token::WhiteSpace(symbols.next()?)) }
8181
None
8282
})
83+
.or_else(|| {
84+
if !symbols.peek()?.is_alphanumeric() {
85+
return Some(Token::CommandToken(CommandToken::CommandOrAlias(String::from(symbols.next()?))))
86+
} None
87+
})
8388
// Or one of "complex" tokens
8489
.or_else(|| parse_number(&mut symbols))
8590
.unwrap_or_else(|| parse_command_or_alias(&mut symbols).expect("Internal exception!"))
@@ -99,7 +104,7 @@ fn parse_command_or_alias<'a>(iter: &mut Peekable<impl Iterator<Item = char> + C
99104
if p.is_numeric() || p.is_whitespace() || p == '.' {return None}
100105
let mut result = String::new();
101106
while let Some(symbol) = iter.peek() {
102-
if symbol.is_whitespace() {break;}
107+
if !symbol.is_alphanumeric() {break;}
103108
result.push(*symbol);
104109
iter.next();
105110
};

0 commit comments

Comments
 (0)