aboutsummaryrefslogtreecommitdiff
path: root/code/src/syntax_highlight/grammar.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-08-30 17:13:23 +0200
committermetamuffin <metamuffin@disroot.org>2022-08-30 17:13:23 +0200
commit5598051d92377dcfc776620aad10eec854a40663 (patch)
tree089aad643f2ed86e75b55d02306bc5322a4559df /code/src/syntax_highlight/grammar.rs
parent802efbca25cb92d8567761361b6513fd57e05578 (diff)
downloadmetamuffin-blog-5598051d92377dcfc776620aad10eec854a40663.tar
metamuffin-blog-5598051d92377dcfc776620aad10eec854a40663.tar.bz2
metamuffin-blog-5598051d92377dcfc776620aad10eec854a40663.tar.zst
extend grammar
Diffstat (limited to 'code/src/syntax_highlight/grammar.rs')
-rw-r--r--code/src/syntax_highlight/grammar.rs35
1 files changed, 34 insertions, 1 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!(),
}
}