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, LessThan,
Comma, Comma,
Backslash, Backslash,
Slash,
Brace, Brace,
Bracket, Bracket,
Paren, Paren,
@ -315,6 +316,13 @@ fn highlight_inner<'a>(
Token::Backslash, Token::Backslash,
)); ));
} }
'/' => {
state.advance_mut(1);
tokens.push(Loc::at(
Region::between(start, state.pos()),
Token::Slash,
));
}
'{' | '}' => { '{' | '}' => {
state.advance_mut(1); state.advance_mut(1);
tokens.push(Loc::at(Region::between(start, state.pos()), Token::Brace)); 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
),
]
)
}
} }

View file

@ -50,7 +50,7 @@ pub fn highlight_roc_code(code: &str) -> String {
Token::Colon => { Token::Colon => {
buf = push_html_span(buf, current_text, "colon"); buf = push_html_span(buf, current_text, "colon");
} }
Token::GreaterThan | Token::Minus | Token::LessThan | Token::Plus | Token::Equals => { Token::Slash | Token::GreaterThan | Token::Minus | Token::LessThan | Token::Plus | Token::Equals => {
buf = push_html_span(buf, current_text, "op"); buf = push_html_span(buf, current_text, "op");
} }
Token::Paren => { Token::Paren => {