diff options
author | June McEnroe <june@causal.agency> | 2020-12-29 22:39:16 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-12-29 22:39:16 -0500 |
commit | 7c70322c7c8e88af93375b89146b0cd6cb8cc7f0 (patch) | |
tree | 109495ff8c3b181f871d38d8b5d34835d23a185c /bin | |
parent | Clean up C lexer (diff) | |
download | src-7c70322c7c8e88af93375b89146b0cd6cb8cc7f0.tar.gz src-7c70322c7c8e88af93375b89146b0cd6cb8cc7f0.zip |
Add make lexer
This is kind of a mess and needs to be cleaned up against more careful reading of the make grammar.
Diffstat (limited to '')
-rw-r--r-- | bin/hilex/Makefile | 1 | ||||
-rw-r--r-- | bin/hilex/ansi.c | 1 | ||||
-rw-r--r-- | bin/hilex/hilex.1 | 20 | ||||
-rw-r--r-- | bin/hilex/hilex.c | 1 | ||||
-rw-r--r-- | bin/hilex/hilex.h | 4 | ||||
-rw-r--r-- | bin/hilex/html.c | 1 | ||||
-rw-r--r-- | bin/hilex/irc.c | 11 | ||||
-rw-r--r-- | bin/hilex/make.l | 102 |
8 files changed, 130 insertions, 11 deletions
diff --git a/bin/hilex/Makefile b/bin/hilex/Makefile index 5f6c1d80..c71738d6 100644 --- a/bin/hilex/Makefile +++ b/bin/hilex/Makefile @@ -5,6 +5,7 @@ OBJS += c.o OBJS += hilex.o OBJS += html.o OBJS += irc.o +OBJS += make.o OBJS += mdoc.o OBJS += text.o diff --git a/bin/hilex/ansi.c b/bin/hilex/ansi.c index a7d22e81..56a10548 100644 --- a/bin/hilex/ansi.c +++ b/bin/hilex/ansi.c @@ -27,6 +27,7 @@ static const char *SGR[ClassCap] = { [Comment] = "34", [String] = "36", [StringFormat] = "36;1;96", + [Interpolation] = "33", }; static void ansiFormat(const char *opts[], enum Class class, const char *text) { diff --git a/bin/hilex/hilex.1 b/bin/hilex/hilex.1 index eb429fb0..2b789f65 100644 --- a/bin/hilex/hilex.1 +++ b/bin/hilex/hilex.1 @@ -1,4 +1,4 @@ -.Dd December 28, 2020 +.Dd December 29, 2020 .Dt HILEX 1 .Os . @@ -84,7 +84,8 @@ and one of the following: .Sy Comment , .Sy String , .Sy StringEscape , -.Sy StringFormat . +.Sy StringFormat , +.Sy Interpolation . . .Pp The options are as follows: @@ -151,21 +152,30 @@ with minimal support for .Xr lex 1 , .Xr yacc 1 and Objective-C input. -Automatically inferred for +Inferred for .Pa *.[chlmy] files. . +.It Cm make +The portable subset of +.Xr make 1 . +Inferred for +.Pa *.mk +and +.Pa Makefile +files. +. .It Cm mdoc The .Xr mdoc 7 language. -Automatically inferred for +Inferred for .Pa *.[1-9] files. . .It Cm text Plain text. -Automatically inferred for +Inferred for .Pa *.txt files. .El diff --git a/bin/hilex/hilex.c b/bin/hilex/hilex.c index 8b824bcd..1fa620e3 100644 --- a/bin/hilex/hilex.c +++ b/bin/hilex/hilex.c @@ -32,6 +32,7 @@ static const struct { const char *pattern; } Lexers[] = { { &LexC, "c", "[.][chlmy]$" }, + { &LexMake, "make", "[.]mk$|^Makefile$" }, { &LexMdoc, "mdoc", "[.][1-9]$" }, { &LexText, "text", "[.]txt$" }, }; diff --git a/bin/hilex/hilex.h b/bin/hilex/hilex.h index 93272bc0..3b796709 100644 --- a/bin/hilex/hilex.h +++ b/bin/hilex/hilex.h @@ -30,7 +30,8 @@ X(Comment) \ X(String) \ X(StringEscape) \ - X(StringFormat) + X(StringFormat) \ + X(Interpolation) enum Class { #define X(class) class, @@ -47,6 +48,7 @@ struct Lexer { }; extern const struct Lexer LexC; +extern const struct Lexer LexMake; extern const struct Lexer LexMdoc; extern const struct Lexer LexText; diff --git a/bin/hilex/html.c b/bin/hilex/html.c index 013b9e81..00c6740e 100644 --- a/bin/hilex/html.c +++ b/bin/hilex/html.c @@ -46,6 +46,7 @@ static const char *Style[ClassCap] = { [Comment] = "color: navy;", [String] = "color: teal;", [StringFormat] = "color: teal; font-weight: bold;", + [Interpolation] = "color: olive;", }; static void styleTabSize(const char *tab) { diff --git a/bin/hilex/irc.c b/bin/hilex/irc.c index 99097a99..acc06fdf 100644 --- a/bin/hilex/irc.c +++ b/bin/hilex/irc.c @@ -22,11 +22,12 @@ #include "hilex.h" static const char *IRC[ClassCap] = { - [Keyword] = "\00315", - [Macro] = "\0033", - [Comment] = "\0032", - [String] = "\00310", - [StringFormat] = "\00311", + [Keyword] = "\00315", + [Macro] = "\0033", + [Comment] = "\0032", + [String] = "\00310", + [StringFormat] = "\00311", + [Interpolation] = "\0037", }; static void ircHeader(const char *opts[]) { diff --git a/bin/hilex/make.l b/bin/hilex/make.l new file mode 100644 index 00000000..e7961eb8 --- /dev/null +++ b/bin/hilex/make.l @@ -0,0 +1,102 @@ +/* Copyright (C) 2020 C. McEnroe <june@causal.agency> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +%option prefix="make" +%option noyywrap + +%{ +#include "hilex.h" +%} + +%s Assign +%x Interp Shell + +ident [._[:alnum:]]+ +target [-/._[:alnum:]]+ +assign [!+:?]?= + +%% + static int pop = INITIAL; + static int depth = 0; + +^"\t" { + BEGIN(pop = Shell); + return Normal; +} +<Shell>{ + "\n" { + BEGIN(pop = INITIAL); + return Normal; + } + [^\n$]+|. { return Normal; } +} + +[[:blank:]] { return Normal; } + +"."(PHONY|PRECIOUS|SUFFIXES)/":"? { + return Keyword; +} + +^{ident}/[[:blank:]]*{assign} { + return Identifier; +} + +{assign} { + BEGIN(pop = Assign); + return Operator; +} +<Assign>{ + "\n" { + BEGIN(pop = INITIAL); + return Normal; + } + [^$[:space:]]+ { return String; } +} + +{target}([[:blank:]]+{target})*/":" { + return IdentifierTag; +} + +^"-"?include { return Macro; } + +"#".* { return Comment; } + +<*>{ + "$"("{"|"(") { + depth++; + BEGIN(Interp); + return Interpolation; + } + "$". { return Interpolation; } +} +<Interp>{ + "}"|")" { + if (!--depth) BEGIN(pop); + return Interpolation; + } + [^${}()]+ { return Interpolation; } +} + +.|\n { return Normal; } + +%{ + (void)yyunput; + (void)input; +%} + +%% + +const struct Lexer LexMake = { yylex, &yyin, &yytext }; |