From 118a437acfb7b53d7522c71bd3f99982724b425b Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Tue, 12 Jan 2021 21:40:11 -0500 Subject: Remove hacky tagging from hilex God that makes the lexers so much simpler. --- bin/hilex/ansi.c | 1 - bin/hilex/c.l | 46 +++------------------------------------------- bin/hilex/hilex.1 | 8 ++------ bin/hilex/hilex.h | 4 +--- bin/hilex/html.c | 41 +++++++++-------------------------------- bin/hilex/make.l | 4 ---- bin/hilex/mdoc.l | 11 ++--------- 7 files changed, 17 insertions(+), 98 deletions(-) diff --git a/bin/hilex/ansi.c b/bin/hilex/ansi.c index cdfcc845..5dc5f127 100644 --- a/bin/hilex/ansi.c +++ b/bin/hilex/ansi.c @@ -22,7 +22,6 @@ static const char *SGR[ClassCap] = { [Keyword] = "37", - [IdentifierTag] = "4", [Macro] = "32", [Comment] = "34", [String] = "36", diff --git a/bin/hilex/c.l b/bin/hilex/c.l index ca99916a..d7a80ae2 100644 --- a/bin/hilex/c.l +++ b/bin/hilex/c.l @@ -21,8 +21,7 @@ #include "hilex.h" %} -%s MacroLine MacroInclude MacroDefine -%s TypeDecl +%s MacroLine MacroInclude %x CharLiteral StringLiteral ident [_[:alpha:]][_[:alnum:]]* @@ -30,7 +29,6 @@ width "*"|[0-9]+ %% static int pop = INITIAL; - static int depth = 0; [[:blank:]]+ { return Normal; } @@ -51,19 +49,6 @@ sizeof|(_A|alignof) { return Number; } -enum|struct|typedef|union { - BEGIN(TypeDecl); - return Keyword; -} -{ident}/[[:space:]]*"{" { - BEGIN(pop); - return IdentifierTag; -} -. { - BEGIN(pop); - REJECT; -} - auto|break|case|const|continue|default|do|else|enum|extern|for|goto|if|inline | register|restrict|return|static|struct|switch|typedef|union|volatile|while | (_A|a)lignas|_Atomic|_Generic|(_N|n)oreturn|(_S|s)tatic_assert | @@ -75,28 +60,14 @@ register|restrict|return|static|struct|switch|typedef|union|volatile|while | BEGIN(pop = MacroInclude); return Macro; } -^"#"[[:blank:]]*define { - BEGIN(pop = MacroDefine); - return Macro; -} ^"#"[[:blank:]]*{ident} { BEGIN(pop = MacroLine); return Macro; } - "<"[^>]+">" { return String; } -{ident}/"(" { - BEGIN(pop = MacroLine); - return IdentifierTag; -} -{ident} { - BEGIN(pop = MacroLine); - return Macro; -} - -{ +{ "\n" { BEGIN(pop = INITIAL); return Normal; @@ -107,14 +78,6 @@ register|restrict|return|static|struct|switch|typedef|union|volatile|while | {ident} { return Identifier; } -{ident}/("["[^]]*"]")*[[:space:]]*"=" | -{ident}/"("[^)]*")"[[:space:]]*"{" { - return (!depth ? IdentifierTag : Identifier); -} -{ident}/"("[^)]*");" { - return (!depth ? IdentifierTag : Identifier); -} - "//"([^\n]|"\\\n")* | "/*"([^*]|"*"[^/])*"*"+"/" { return Comment; @@ -160,10 +123,7 @@ register|restrict|return|static|struct|switch|typedef|union|volatile|while | [^%\\""]+|. { return String; } } -"{" { depth++; REJECT; } -"}" { depth--; REJECT; } - -. { +. { return Macro; } diff --git a/bin/hilex/hilex.1 b/bin/hilex/hilex.1 index 2b789f65..858c8565 100644 --- a/bin/hilex/hilex.1 +++ b/bin/hilex/hilex.1 @@ -1,4 +1,4 @@ -.Dd December 29, 2020 +.Dd January 12, 2021 .Dt HILEX 1 .Os . @@ -79,7 +79,6 @@ and one of the following: .Sy Number , .Sy Keyword , .Sy Identifier , -.Sy IdentifierTag , .Sy Macro , .Sy Comment , .Sy String , @@ -90,10 +89,7 @@ and one of the following: .Pp The options are as follows: .Bl -tag -width "title=..." -.It Cm anchor -Output identifier tags as anchor links. -. -.It Cm css Ns = Ns Ar url +.It Cm style Ns = Ns Ar url With .Cm document , output a diff --git a/bin/hilex/hilex.h b/bin/hilex/hilex.h index fa16f1b6..f01bc583 100644 --- a/bin/hilex/hilex.h +++ b/bin/hilex/hilex.h @@ -25,7 +25,6 @@ X(Number) \ X(Keyword) \ X(Identifier) \ - X(IdentifierTag) \ X(Macro) \ X(Comment) \ X(String) \ @@ -53,11 +52,10 @@ extern const struct Lexer LexMdoc; extern const struct Lexer LexText; #define ENUM_OPTION \ - X(Anchor, "anchor") \ - X(CSS, "css") \ X(Document, "document") \ X(Inline, "inline") \ X(Monospace, "monospace") \ + X(Style, "style") \ X(Tab, "tab") \ X(Title, "title") diff --git a/bin/hilex/html.c b/bin/hilex/html.c index bec1d6a8..1cc83c47 100644 --- a/bin/hilex/html.c +++ b/bin/hilex/html.c @@ -39,9 +39,8 @@ static const char *Class[ClassCap] = { #undef X }; -static const char *Style[ClassCap] = { +static const char *Styles[ClassCap] = { [Keyword] = "color: dimgray;", - [IdentifierTag] = "color: inherit;", [Macro] = "color: green;", [Comment] = "color: navy;", [String] = "color: teal;", @@ -64,9 +63,9 @@ static void htmlHeader(const char *opts[]) { if (opts[Title]) htmlEscape(opts[Title]); printf("\n"); - if (opts[CSS]) { + if (opts[Style]) { printf("\n"); } else if (!opts[Inline]) { printf("\n"); } @@ -103,33 +96,17 @@ static void htmlFooter(const char *opts[]) { if (opts[Document]) printf("\n"); } -static void htmlAnchor(const char *opts[], const char *text) { - if (opts[Inline]) { - printf(""); - htmlEscape(text); - printf(""); -} - static void htmlFormat(const char *opts[], enum Class class, const char *text) { - if (opts[Anchor] && class == IdentifierTag) { - htmlAnchor(opts, text); - } else if (class == Normal) { - htmlEscape(text); - } else { + if (class != Normal) { if (opts[Inline]) { - printf("", Style[class] ? Style[class] : ""); + printf("", Styles[class] ? Styles[class] : ""); } else { printf("", Class[class]); } htmlEscape(text); printf(""); + } else { + htmlEscape(text); } } diff --git a/bin/hilex/make.l b/bin/hilex/make.l index 31b85574..952c589d 100644 --- a/bin/hilex/make.l +++ b/bin/hilex/make.l @@ -73,10 +73,6 @@ operator [:!]|:: ^"-"?include { return Macro; } -{target}([[:blank:]]+{target})*/{operator} { - return IdentifierTag; -} - {target} { return Identifier; } "#"([^\\\n]|"\\"[^\n]|"\\\n")* { return Comment; } diff --git a/bin/hilex/mdoc.l b/bin/hilex/mdoc.l index 4db147c8..2680b722 100644 --- a/bin/hilex/mdoc.l +++ b/bin/hilex/mdoc.l @@ -21,7 +21,7 @@ #include "hilex.h" %} -%s MacroLine Heading +%s MacroLine %% @@ -34,17 +34,12 @@ ^".\\\"".* { return Comment; } -{ +{ "\n" { BEGIN(0); 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] { @@ -54,8 +49,6 @@ "\""([^""]|"\\\"")*"\"" { return String; } } -[^[:space:]].* { return IdentifierTag; } - "\\"(.|"("..|"["[^]]*"]") { return String; } [^.\\""[:space:]]+ { return Normal; } -- cgit 1.4.1