diff options
author | metamuffin <metamuffin@disroot.org> | 2022-08-30 17:13:23 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-08-30 17:13:23 +0200 |
commit | 5598051d92377dcfc776620aad10eec854a40663 (patch) | |
tree | 089aad643f2ed86e75b55d02306bc5322a4559df | |
parent | 802efbca25cb92d8567761361b6513fd57e05578 (diff) | |
download | metamuffin-blog-5598051d92377dcfc776620aad10eec854a40663.tar metamuffin-blog-5598051d92377dcfc776620aad10eec854a40663.tar.bz2 metamuffin-blog-5598051d92377dcfc776620aad10eec854a40663.tar.zst |
extend grammar
-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 | ||||
-rw-r--r-- | content/articles/2022-08-29-blog-test.md | 9 |
4 files changed, 48 insertions, 5 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", } } diff --git a/content/articles/2022-08-29-blog-test.md b/content/articles/2022-08-29-blog-test.md index 2b65444..cdbeab0 100644 --- a/content/articles/2022-08-29-blog-test.md +++ b/content/articles/2022-08-29-blog-test.md @@ -11,10 +11,15 @@ _italic_ **bold** `code` [Link](https://metamuffin.org/) Look at this code here. ```rs -fn main() { 1 + 1 } +struct Impossible<T> { + something: HashMap<usize, T>, + itself: Impossible, +} + pub async fn useless(s: Box<dyn Write>) -> impl Future<usize> { - todo!() + todo!() // this panics } +fn main() { 1 + "blub" } ``` As you can see, its pointless i.e. no points |