aboutsummaryrefslogtreecommitdiff
path: root/code/src/syntax_highlight/grammar.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-09-25 20:42:10 +0200
committermetamuffin <metamuffin@disroot.org>2022-09-25 20:42:10 +0200
commit0a18eae178a23e7f7bfd88c37502e5e8c1fdf64a (patch)
treefb5b1aa5f9a8d023b2edbc9e89b5d2e4844a42eb /code/src/syntax_highlight/grammar.rs
parente3edf18503b3975ccec3b33c0cb9e7f0888bd031 (diff)
downloadmetamuffin-blog-0a18eae178a23e7f7bfd88c37502e5e8c1fdf64a.tar
metamuffin-blog-0a18eae178a23e7f7bfd88c37502e5e8c1fdf64a.tar.bz2
metamuffin-blog-0a18eae178a23e7f7bfd88c37502e5e8c1fdf64a.tar.zst
(the commit before proper parsers will replace everything™™)
Diffstat (limited to 'code/src/syntax_highlight/grammar.rs')
-rw-r--r--code/src/syntax_highlight/grammar.rs53
1 files changed, 30 insertions, 23 deletions
diff --git a/code/src/syntax_highlight/grammar.rs b/code/src/syntax_highlight/grammar.rs
index 0878b33..0cecac9 100644
--- a/code/src/syntax_highlight/grammar.rs
+++ b/code/src/syntax_highlight/grammar.rs
@@ -1,3 +1,8 @@
+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" => &[
@@ -11,41 +16,43 @@ pub fn grammar_for(syntax: &str) -> &'static [(&'static str, &'static [&'static
(
"type",
&[
- "[A-Z][a-z0-9]*",
- "bool",
- "usize",
- "u8",
- "u16",
- "u32",
- "u64",
- "u128",
- "i8",
- "i16",
- "i32",
- "i64",
- "i128",
- "isize",
- "f32",
- "f64",
+ 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_]*!)\\s*"]),
- ("identifier", &["([a-z_][A-Za-z0-9_]*)\\s*\\("]),
- ("literal", &["\".*?\"", "\\d", "true", "false"]),
+ ("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", "as",
- "import",
+ "from", "for", "def", "if", "else", "elif", "while", "with", "in", "assert",
+ "global", "nonlocal", "as", "import",
],
),
("comment", &["(?m)(#.*)$"]),
- ("identifier", &["([a-z_][A-Za-z0-9_]*)\\s*\\("]),
- ("literal", &["b?\".*?\"", "\\d", "true", "false"]),
+ ("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