diff options
-rw-r--r-- | bin/hilex/ansi.c | 9 | ||||
-rw-r--r-- | bin/hilex/hilex.h | 1 | ||||
-rw-r--r-- | bin/hilex/mdoc.l | 16 |
3 files changed, 21 insertions, 5 deletions
diff --git a/bin/hilex/ansi.c b/bin/hilex/ansi.c index fab9c2ed..4b8e1b69 100644 --- a/bin/hilex/ansi.c +++ b/bin/hilex/ansi.c @@ -20,8 +20,9 @@ #include "hilex.h" -static const char *Color[ClassCap] = { +static const char *SGR[ClassCap] = { [Keyword] = "37", + [Tag] = "4", [Macro] = "32", [Comment] = "34", [String] = "36", @@ -30,15 +31,15 @@ static const char *Color[ClassCap] = { static void format(const char *opts[], enum Class class, const char *text) { (void)opts; - if (!Color[class]) { + if (!SGR[class]) { printf("%s", text); return; } // Set color on each line for piping to less -R: for (const char *nl; (nl = strchr(text, '\n')); text = &nl[1]) { - printf("\33[%sm%.*s\33[m\n", Color[class], (int)(nl - text), text); + printf("\33[%sm%.*s\33[m\n", SGR[class], (int)(nl - text), text); } - if (*text) printf("\33[%sm%s\33[m", Color[class], text); + if (*text) printf("\33[%sm%s\33[m", SGR[class], text); } const struct Formatter FormatANSI = { .format = format }; diff --git a/bin/hilex/hilex.h b/bin/hilex/hilex.h index 00c7f53b..442094c8 100644 --- a/bin/hilex/hilex.h +++ b/bin/hilex/hilex.h @@ -25,6 +25,7 @@ X(Number) \ X(Keyword) \ X(Identifier) \ + X(Tag) \ X(Macro) \ X(Comment) \ X(String) \ diff --git a/bin/hilex/mdoc.l b/bin/hilex/mdoc.l index d5c76a04..cb4c248e 100644 --- a/bin/hilex/mdoc.l +++ b/bin/hilex/mdoc.l @@ -21,7 +21,7 @@ #include "hilex.h" %} -%s MacroLine +%s MacroLine Heading %% @@ -38,6 +38,11 @@ return Normal; } + S[hs] { + BEGIN(Heading); + return Keyword; + } + %[ABCDIJNOPQRTUV]|A[cdnopqrt]|B[cdfkloqtx]|Br[coq]|Bsx|C[dm]|D[1bcdloqtvx] | E[cdfklmnorsvx]|F[acdlnortx]|Hf|I[cnt]|L[bikp]|M[st]|N[dmosx]|O[copstx] | P[acfopq]|Q[cloq]|R[esv]|S[chmoqstxy]|T[an]|U[dx]|V[at]|X[cor] { @@ -47,6 +52,15 @@ "\""([^""]|"\\\"")*"\"" { return String; } } +<Heading>{ + "\n" { + BEGIN(0); + return Normal; + } + + [^[:space:]].* { return Tag; } +} + "\\"(.|"("..|"["[^]]*"]") { return String; } [[:blank:]]+|[^.\n""\\[:space:]]+|.|\n { return Normal; } |