diff options
author | metamuffin <metamuffin@disroot.org> | 2022-09-26 14:14:58 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-09-26 14:14:58 +0200 |
commit | 15d78464ba9a717a71e1dc47a4101c8b13ec6581 (patch) | |
tree | 43def89ffd6e9c2ff80e7f7eeecec6fcf18c4e92 /code/src/syntax_highlight/grammar.rs | |
parent | 0a18eae178a23e7f7bfd88c37502e5e8c1fdf64a (diff) | |
download | metamuffin-blog-15d78464ba9a717a71e1dc47a4101c8b13ec6581.tar metamuffin-blog-15d78464ba9a717a71e1dc47a4101c8b13ec6581.tar.bz2 metamuffin-blog-15d78464ba9a717a71e1dc47a4101c8b13ec6581.tar.zst |
syntax highlighting with syntect
Diffstat (limited to 'code/src/syntax_highlight/grammar.rs')
-rw-r--r-- | code/src/syntax_highlight/grammar.rs | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/code/src/syntax_highlight/grammar.rs b/code/src/syntax_highlight/grammar.rs deleted file mode 100644 index 0cecac9..0000000 --- a/code/src/syntax_highlight/grammar.rs +++ /dev/null @@ -1,67 +0,0 @@ -const CONST: &str = "[\\. \\(,=^]([A-Z][A-Z0-9_]*)[\\. ,\\)=$]"; -const TYPE: &str = "[\\. \\(,=^]([A-Z][a-zA-Z0-9_]*)[\\. ,\\)\\(=$]"; -const IDENT: &str = "[\\. \\(,=^]([a-z][a-zA-Z0-9_]*)[\\. ,\\)=$]"; -const FUNC: &str = "[\\. \\(,=^]([a-z][A-Z0-9_]*)\\("; - -pub fn grammar_for(syntax: &str) -> &'static [(&'static str, &'static [&'static str])] { - match syntax { - "rs" | "rust" => &[ - ( - "keyword", - &[ - "fn", "pub", "async", "return", "if", "else", "let", "for", "in", "while", - "loop", "impl", "for", "trait", "struct", "enum", "dyn", - ], - ), - ( - "type", - &[ - TYPE, "bool", "usize", "u8", "u16", "u32", "u64", "u128", "i8", "i16", "i32", - "i64", "i128", "isize", "f32", "f64", - ], - ), - ("constant", &[CONST]), - ("comment", &["(?m)(//.*)$", "(?ms)/\\*.*?\\*/"]), - ("macro", &["[\\. ,=^]([a-z_][A-Za-z0-9_]*!)[\\. ,=$]"]), - ("identifier", &[IDENT]), - ("function", &[FUNC]), - ( - "literal", - &["\".*?\"", "(0x|0o|0b)[0-9a-f]+", "\\d+", "true", "false"], - ), - ], - "py" | "python" => &[ - ("type", &["bytes", "bool", "int", "str", "float"]), - ( - "keyword", - &[ - "from", "for", "def", "if", "else", "elif", "while", "with", "in", "assert", - "global", "nonlocal", "as", "import", - ], - ), - ("comment", &["(?m)(#.*)$"]), - ("constant", &[CONST]), - ("identifier", &[IDENT]), - ( - "literal", - &[ - "b?f?\".*?\"", - "b?f?'.*?'", - "(0x|0o|0b)[0-9a-f]+", - "\\d+", - "true", - "false", - ], - ), - ], - "tree" => &[("keyword", &["[├─└│]+"])], - // makefile doesnt really match the token-kinds, i'll just use something that looks goo - "makefile" | "mk" => &[ - ("comment", &["(?m)(#.*)$"]), - ("literal", &[".+: "]), - ("macro", &["\\$\\(\\w+\\)"]), - ("type", &["\\$@", "\\$<"]), - ], - _ => &[], - } -} |