aboutsummaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-08-30 18:54:52 +0200
committermetamuffin <metamuffin@disroot.org>2022-08-30 18:54:52 +0200
commit4b1f352dbaf50ff60c434a5888048768820a3ff2 (patch)
tree540a5a3e7575a5002d9c05120cf55922a4ac5044 /code
parent7f84570e65be168a8e0a6e7029f52ca692885cd8 (diff)
downloadmetamuffin-blog-4b1f352dbaf50ff60c434a5888048768820a3ff2.tar
metamuffin-blog-4b1f352dbaf50ff60c434a5888048768820a3ff2.tar.bz2
metamuffin-blog-4b1f352dbaf50ff60c434a5888048768820a3ff2.tar.zst
tree grammar + flip tuple
Diffstat (limited to 'code')
-rw-r--r--code/src/syntax_highlight/grammar.rs22
-rw-r--r--code/src/syntax_highlight/mod.rs2
2 files changed, 16 insertions, 8 deletions
diff --git a/code/src/syntax_highlight/grammar.rs b/code/src/syntax_highlight/grammar.rs
index ba703e7..dad2eec 100644
--- a/code/src/syntax_highlight/grammar.rs
+++ b/code/src/syntax_highlight/grammar.rs
@@ -1,14 +1,15 @@
-pub fn grammar_for(syntax: &str) -> &'static [(&'static [&'static str], &'static str)] {
+pub fn grammar_for(syntax: &str) -> &'static [(&'static str, &'static [&'static str])] {
match syntax {
"rs" => &[
(
+ "keyword",
&[
"fn", "pub", "async", "return", "if", "else", "let", "for", "while", "loop",
"impl", "for", "trait", "struct", "enum",
],
- "keyword",
),
(
+ "type",
&[
"[A-Z][a-z]*",
"bool",
@@ -27,12 +28,19 @@ pub fn grammar_for(syntax: &str) -> &'static [(&'static [&'static str], &'static
"f32",
"f64",
],
- "type",
),
- (&["(?m)(//.*)$"], "comment"),
- (&["([a-z_][A-Za-z0-9_]*!)\\s*"], "macro"),
- (&["([a-z_][A-Za-z0-9_]*)\\s*\\("], "identifier"),
- (&["\".*?\"", "\\d", "true", "false"], "literal"),
+ ("comment", &["(?m)(//.*)$", "(?ms)/\\*.*?\\*/"]),
+ ("macro", &["([a-z_][A-Za-z0-9_]*!)\\s*"]),
+ ("identifier", &["([a-z_][A-Za-z0-9_]*)\\s*\\("]),
+ ("literal", &["\".*?\"", "\\d", "true", "false"]),
+ ],
+ "tree" => &[("keyword", &["[├─└│]+"])],
+ // makefile doesnt really match the token-kinds, i'll just use something that looks goo
+ "makefile" => &[
+ ("comment", &["(?m)(#.*)$"]),
+ ("literal", &[".+:"]),
+ ("macro", &["\\$\\(\\w+\\)"]),
+ ("type", &["\\$@", "\\$<"]),
],
_ => &[],
}
diff --git a/code/src/syntax_highlight/mod.rs b/code/src/syntax_highlight/mod.rs
index 515de28..46bf2a0 100644
--- a/code/src/syntax_highlight/mod.rs
+++ b/code/src/syntax_highlight/mod.rs
@@ -7,7 +7,7 @@ use synoptic::{Highlighter, Token};
pub fn syntax_highlight(lang: &str, source: &str) -> String {
let mut h = Highlighter::new();
- for (regex, kind) in grammar_for(lang) {
+ for (kind, regex) in grammar_for(lang) {
h.join(regex, kind).unwrap();
}
let highlighting = h.run(source);