diff options
Diffstat (limited to 'code')
-rw-r--r-- | code/src/syntax_highlight/grammar.rs | 35 | ||||
-rw-r--r-- | code/src/syntax_highlight/mod.rs | 2 | ||||
-rw-r--r-- | code/src/syntax_highlight/theme.rs | 7 |
3 files changed, 41 insertions, 3 deletions
diff --git a/code/src/syntax_highlight/grammar.rs b/code/src/syntax_highlight/grammar.rs index 95417ab..9e6caae 100644 --- a/code/src/syntax_highlight/grammar.rs +++ b/code/src/syntax_highlight/grammar.rs @@ -1,6 +1,39 @@ pub fn grammar_for(syntax: &str) -> &'static [(&'static [&'static str], &'static str)] { match syntax { - "rs" => &[(&["fn", "pub", "async"], "keyword")], + "rs" => &[ + ( + &[ + "fn", "pub", "async", "return", "if", "else", "let", "for", "while", "loop", + "impl", "for", "trait", "struct", "enum", + ], + "keyword", + ), + ( + &[ + "[A-Z][a-z]*", + "bool", + "usize", + "u8", + "u16", + "u32", + "u64", + "u128", + "i8", + "i16", + "i32", + "i64", + "i128", + "isize", + "f32", + "f64", + ], + "type", + ), + (&["(?m)(//.*)$"], "comment"), + (&["([a-z_][A-Za-z0-9_]*!)\\s*"], "macro"), + (&["([a-z_][A-Za-z0-9_]*)\\s*\\("], "identifier"), + (&["\".*?\"", "\\d", "true", "false"], "literal"), + ], _ => unreachable!(), } } diff --git a/code/src/syntax_highlight/mod.rs b/code/src/syntax_highlight/mod.rs index 688b010..515de28 100644 --- a/code/src/syntax_highlight/mod.rs +++ b/code/src/syntax_highlight/mod.rs @@ -14,7 +14,6 @@ pub fn syntax_highlight(lang: &str, source: &str) -> String { let mut out = String::new(); for (_c, row) in highlighting.iter().enumerate() { - eprintln!("{row:?}"); for tok in row { match tok { Token::Start(kind) => out += &format!("<span style=\"color:{}\">", theme(kind)), @@ -24,6 +23,5 @@ pub fn syntax_highlight(lang: &str, source: &str) -> String { } out += "\n" } - eprintln!("{out:?}"); out } diff --git a/code/src/syntax_highlight/theme.rs b/code/src/syntax_highlight/theme.rs index 40434ad..77018db 100644 --- a/code/src/syntax_highlight/theme.rs +++ b/code/src/syntax_highlight/theme.rs @@ -1,6 +1,13 @@ pub fn theme(kind: &str) -> &'static str { match kind { "keyword" => "#9999ff", + "macro" => "#ff2863", + "literal" => "#26a6ff", + "functions" => "#26ffbc", + "types" => "#26ff34", + "identifier" => "#ccff26", + "" => "#ff7c26", + "comment" => "#6e6e6e", _ => "#ff00ff", } } |