summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-01-12 21:40:11 -0500
committerJune McEnroe <june@causal.agency>2021-01-12 21:40:11 -0500
commit47940e2a528e30903c68abb6c0246cb86772d389 (patch)
tree63fe27534734a611699c1eeff82f2f0090febcfa /bin
parentAdd htagml -i (diff)
downloadsrc-47940e2a528e30903c68abb6c0246cb86772d389.tar.gz
src-47940e2a528e30903c68abb6c0246cb86772d389.zip
Remove hacky tagging from hilex
God that makes the lexers so much simpler.
Diffstat (limited to 'bin')
-rw-r--r--bin/hilex/ansi.c1
-rw-r--r--bin/hilex/c.l46
-rw-r--r--bin/hilex/hilex.18
-rw-r--r--bin/hilex/hilex.h4
-rw-r--r--bin/hilex/html.c41
-rw-r--r--bin/hilex/make.l4
-rw-r--r--bin/hilex/mdoc.l11
7 files changed, 17 insertions, 98 deletions
diff --git a/bin/hilex/ansi.c b/bin/hilex/ansi.c
index 56a10548..114d03a6 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 e89d3adc..21e7d44b 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;
-}
-<TypeDecl>{ident}/[[:space:]]*"{" {
-	BEGIN(pop);
-	return IdentifierTag;
-}
-<TypeDecl>. {
-	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;
 }
-
 <MacroInclude>"<"[^>]+">" {
 	return String;
 }
-<MacroDefine>{ident}/"(" {
-	BEGIN(pop = MacroLine);
-	return IdentifierTag;
-}
-<MacroDefine>{ident} {
-	BEGIN(pop = MacroLine);
-	return Macro;
-}
-
-<MacroLine,MacroInclude,MacroDefine>{
+<MacroLine,MacroInclude>{
 	"\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);
-}
-<TypeDecl>{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; }
-
-<MacroLine,MacroInclude,MacroDefine>. {
+<MacroLine,MacroInclude>. {
 	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 3b796709..88a71a51 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 00c6740e..59914d06 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("</title>\n");
 
-	if (opts[CSS]) {
+	if (opts[Style]) {
 		printf("<link rel=\"stylesheet\" href=\"");
-		htmlEscape(opts[CSS]);
+		htmlEscape(opts[Style]);
 		printf("\">\n");
 	} else if (!opts[Inline]) {
 		printf("<style>\n");
@@ -76,14 +75,8 @@ static void htmlHeader(const char *opts[]) {
 			printf(" }\n");
 		}
 		for (enum Class class = 0; class < ClassCap; ++class) {
-			if (!Style[class]) continue;
-			printf(".hilex.%s { %s }\n", Class[class], Style[class]);
-		}
-		if (opts[Anchor]) {
-			printf(
-				".hilex.%s:target { color: goldenrod; outline: none; }\n",
-				Class[IdentifierTag]
-			);
+			if (!Styles[class]) continue;
+			printf(".hilex.%s { %s }\n", Class[class], Styles[class]);
 		}
 		printf("</style>\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("<a style=\"%s\" id=\"", Style[IdentifierTag]);
-	} else {
-		printf("<a class=\"hilex %s\" id=\"", Class[IdentifierTag]);
-	}
-	htmlEscape(text);
-	printf("\" href=\"#");
-	htmlEscape(text);
-	printf("\">");
-	htmlEscape(text);
-	printf("</a>");
-}
-
 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("<span style=\"%s\">", Style[class] ? Style[class] : "");
+			printf("<span style=\"%s\">", Styles[class] ? Styles[class] : "");
 		} else {
 			printf("<span class=\"hilex %s\">", Class[class]);
 		}
 		htmlEscape(text);
 		printf("</span>");
+	} else {
+		htmlEscape(text);
 	}
 }
 
diff --git a/bin/hilex/make.l b/bin/hilex/make.l
index e9d3c84d..e7f3def5 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 3dbba639..a31b6a2e 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; }
 
-<MacroLine,Heading>{
+<MacroLine>{
 	"\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; }
 }
 
-<Heading>[^[:space:]].* { return IdentifierTag; }
-
 "\\"(.|"("..|"["[^]]*"]") { return String; }
 
 [^.\\""[:space:]]+ { return Normal; }