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/Cargo.toml | 2 +- code/src/syntax_highlight/grammar.rs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/code/Cargo.toml b/code/Cargo.toml index 3547fd4..c528649 100644 --- a/code/Cargo.toml +++ b/code/Cargo.toml @@ -9,4 +9,4 @@ clap = { version = "3.2.17", features = ["derive"] } # bloated argument parser anyhow = "1.0.62" # error stuff markdown = "0.3.0" # markdown parser iso8601 = "0.5.0" # date parsing -synoptic = "1.2.0" # syntax highlighting +synoptic = "1.2.0" # syntax highlighting 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