add support for slashes

This commit is contained in:
Luke Boswell 2023-03-01 19:06:15 +11:00
parent 093f8e297d
commit f51aef42bb
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
2 changed files with 32 additions and 1 deletions

View file

@ -39,6 +39,7 @@ pub enum Token {
LessThan,
Comma,
Backslash,
Slash,
Brace,
Bracket,
Paren,
@ -315,6 +316,13 @@ fn highlight_inner<'a>(
Token::Backslash,
));
}
'/' => {
state.advance_mut(1);
tokens.push(Loc::at(
Region::between(start, state.pos()),
Token::Slash,
));
}
'{' | '}' => {
state.advance_mut(1);
tokens.push(Loc::at(Region::between(start, state.pos()), Token::Brace));
@ -631,4 +639,27 @@ mod tests {
]
)
}
#[test]
fn test_highlight_slash() {
let text = "first / second";
let tokens = highlight(text);
assert_eq!(
tokens,
vec![
Loc::at(
Region::between(Position::new(0), Position::new(5)),
Token::LowerIdent
),
Loc::at(
Region::between(Position::new(6), Position::new(7)),
Token::Slash
),
Loc::at(
Region::between(Position::new(8), Position::new(14)),
Token::LowerIdent
),
]
)
}
}