summary refs log tree commit diff
path: root/bin/hi.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-02-08 21:32:09 -0500
committerJune McEnroe <june@causal.agency>2019-02-08 21:32:09 -0500
commit10b2f09cb8a5054037529a62bf111d297ee86955 (patch)
tree49378bdd7530132da745548308193e4cffa8d03a /bin/hi.c
parentUse [] to quote special characters in regex (diff)
downloadsrc-10b2f09cb8a5054037529a62bf111d297ee86955.tar.gz
src-10b2f09cb8a5054037529a62bf111d297ee86955.zip
Add sh syntax to hi
Diffstat (limited to 'bin/hi.c')
-rw-r--r--bin/hi.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/bin/hi.c b/bin/hi.c
index 5101ead3..182fc3b1 100644
--- a/bin/hi.c
+++ b/bin/hi.c
@@ -1,3 +1,4 @@
+/* vim: set foldmethod=marker foldlevel=0: */
 /* Copyright (C) 2019  C. McEnroe <june@causal.agency>
  *
  * This program is free software: you can redistribute it and/or modify
@@ -167,6 +168,54 @@ static const struct Syntax MdocSyntax[] = {
 };
 // }}}
 
+// sh syntax {{{
+static const struct Syntax ShSyntax[] = {
+	{ Keyword, .subexp = 2, .pattern =
+		WB "("
+		"!|case|do|done|elif|else|esac|fi|for|if|in|then|until|while"
+		")" WB
+	},
+	{ Keyword, .subexp = 2, .pattern =
+		WB "("
+		"alias|bg|cd|command|false|fc|fg|getopts|jobs|kill|newgrp|pwd|read"
+		"|true|umask|unalias|wait"
+		")" WB
+	},
+	{ Keyword, .subexp = 2, .pattern =
+		WB "("
+		"[.:]|break|continue|eval|exec|exit|export|local|readonly|return|set"
+		"|shift|times|trap|unset"
+		")" WB
+	},
+	{ String,
+		.pattern = PATTERN_DQ },
+	{ String, .subexp = 1,
+		.pattern = "<<-?" WS "EOF.*(\n)",
+		.pattend = "^\t*EOF$" },
+	{ Escape, .parent = SET(String),
+		.pattern = "[\\][\"$\\`]" },
+	{ String, .parent = ~SET(Escape),
+		.pattern = "[\\]." },
+	{ Interp, .parent = ~SET(Escape),
+		.pattern = "[$]([!#$*-?@]|[_[:alnum:]]+)" },
+	{ Interp, .parent = ~SET(Escape),
+		.pattern = "[$][{][^}]*[}]" },
+	{ Interp, .parent = ~SET(Escape),
+		.pattern = "[$][(][^)]*[)]" "|" "`[^`]*`" },
+	{ String,
+		.pattern = "'[^']*'" },
+	{ String, .subexp = 1,
+		.pattern = "<<-?" WS "'EOF'.*(\n)",
+		.pattend = "^\t*EOF$" },
+	{ Normal, .parent = SET(String),
+		.pattern = "^\t*EOF$" },
+	{ Comment, .parent = ~SET(String), .subexp = 2,
+		.pattern = "(^|" WS ")" "(#.*)" },
+	{ Todo, .parent = SET(Comment),
+		.pattern = PATTERN_TODO },
+};
+// }}}
+
 static const struct Language {
 	const char *name;
 	const char *pattern;
@@ -176,6 +225,7 @@ static const struct Language {
 	{ "c",    "[.][ch]$", CSyntax, ARRAY_LEN(CSyntax) },
 	{ "make", "[.]mk$|^Makefile$", MakeSyntax, ARRAY_LEN(MakeSyntax) },
 	{ "mdoc", "[.][1-9]$", MdocSyntax, ARRAY_LEN(MdocSyntax) },
+	{ "sh",   "[.]sh$", ShSyntax, ARRAY_LEN(ShSyntax) },
 };
 
 static regex_t compile(const char *pattern, int flags) {