From a3f5d3f6d9bb5a42c913f6af2153c51a122a0bd7 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 25 Sep 2022 13:45:26 +0200 Subject: basic python syntax --- code/src/syntax_highlight/grammar.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'code/src/syntax_highlight') diff --git a/code/src/syntax_highlight/grammar.rs b/code/src/syntax_highlight/grammar.rs index 82ae243..18ba9e2 100644 --- a/code/src/syntax_highlight/grammar.rs +++ b/code/src/syntax_highlight/grammar.rs @@ -1,6 +1,6 @@ pub fn grammar_for(syntax: &str) -> &'static [(&'static str, &'static [&'static str])] { match syntax { - "rs" => &[ + "rs" | "rust" => &[ ( "keyword", &[ @@ -34,9 +34,22 @@ pub fn grammar_for(syntax: &str) -> &'static [(&'static str, &'static [&'static ("identifier", &["([a-z_][A-Za-z0-9_]*)\\s*\\("]), ("literal", &["\".*?\"", "\\d", "true", "false"]), ], + "py" | "python" => &[ + ("type", &["bytes", "bool", "int", "str", "float"]), + ( + "keyword", + &[ + "from", "for", "def", "if", "else", "elif", "while", "with", "in", "as", + "import", + ], + ), + ("comment", &["(?m)(#.*)$"]), + ("identifier", &["([a-z_][A-Za-z0-9_]*)\\s*\\("]), + ("literal", &["b?\".*?\"", "\\d", "true", "false"]), + ], "tree" => &[("keyword", &["[├─└│]+"])], // makefile doesnt really match the token-kinds, i'll just use something that looks goo - "makefile" => &[ + "makefile" | "mk" => &[ ("comment", &["(?m)(#.*)$"]), ("literal", &[".+: "]), ("macro", &["\\$\\(\\w+\\)"]), -- cgit v1.2.3-70-g09d2