diff options
author | metamuffin <metamuffin@disroot.org> | 2022-09-25 13:45:26 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-09-25 13:45:26 +0200 |
commit | a3f5d3f6d9bb5a42c913f6af2153c51a122a0bd7 (patch) | |
tree | e2260e7b3d824d404e04aa06d611e32b794c849c | |
parent | 3595cf34b9520b7e548972dec8b787d80ecd0049 (diff) | |
download | metamuffin-blog-a3f5d3f6d9bb5a42c913f6af2153c51a122a0bd7.tar metamuffin-blog-a3f5d3f6d9bb5a42c913f6af2153c51a122a0bd7.tar.bz2 metamuffin-blog-a3f5d3f6d9bb5a42c913f6af2153c51a122a0bd7.tar.zst |
basic python syntax
-rw-r--r-- | code/Cargo.toml | 2 | ||||
-rw-r--r-- | 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+\\)"]), |