From 61acea4f1e463303ecad7c7ebf4f85dfe9253c13 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Mon, 28 Dec 2020 22:44:25 -0500 Subject: Add mdoc lexer --- bin/hilex/Makefile | 1 + bin/hilex/hilex.c | 2 ++ bin/hilex/hilex.h | 1 + bin/hilex/mdoc.l | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 bin/hilex/mdoc.l (limited to 'bin') diff --git a/bin/hilex/Makefile b/bin/hilex/Makefile index 4a930757..3fd11069 100644 --- a/bin/hilex/Makefile +++ b/bin/hilex/Makefile @@ -3,6 +3,7 @@ CFLAGS += -std=c11 -Wall -Wextra -Wpedantic OBJS += ansi.o OBJS += c.o OBJS += hilex.o +OBJS += mdoc.o OBJS += text.o hilex: ${OBJS} diff --git a/bin/hilex/hilex.c b/bin/hilex/hilex.c index 5b40f280..6e308249 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]$" }, + { &LexMdoc, "mdoc", "[.][1-9]$" }, { &LexText, "text", "[.]txt$" }, }; @@ -123,6 +124,7 @@ int main(int argc, char *argv[]) { *lexer->in = file; if (formatter->header) formatter->header(NULL); for (enum Class class; None != (class = lexer->lex());) { + assert(class < ClassCap); formatter->format(NULL, class, *lexer->text); } if (formatter->footer) formatter->footer(NULL); diff --git a/bin/hilex/hilex.h b/bin/hilex/hilex.h index 5d11a875..00c7f53b 100644 --- a/bin/hilex/hilex.h +++ b/bin/hilex/hilex.h @@ -46,6 +46,7 @@ struct Lexer { }; extern const struct Lexer LexC; +extern const struct Lexer LexMdoc; extern const struct Lexer LexText; typedef void Header(const char *opts[]); diff --git a/bin/hilex/mdoc.l b/bin/hilex/mdoc.l new file mode 100644 index 00000000..d5c76a04 --- /dev/null +++ b/bin/hilex/mdoc.l @@ -0,0 +1,61 @@ +/* Copyright (C) 2020 June McEnroe + * + * 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 . + */ + +%option prefix="mdoc" +%option noyywrap + +%{ +#include "hilex.h" +%} + +%s MacroLine + +%% + +^"." { + BEGIN(MacroLine); + return Keyword; +} + +^".\\\"".* { return Comment; } + +{ + "\n" { + BEGIN(0); + return Normal; + } + + %[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] { + return Keyword; + } + + "\""([^""]|"\\\"")*"\"" { return String; } +} + +"\\"(.|"("..|"["[^]]*"]") { return String; } + +[[:blank:]]+|[^.\n""\\[:space:]]+|.|\n { return Normal; } + +%{ + (void)yyunput; + (void)input; +%} + +%% + +const struct Lexer LexMdoc = { yylex, &yyin, &yytext }; -- cgit 1.4.1 .editrc before applying -v or -eJune McEnroe 2020-03-09Add \? exit status prompt expansionJune McEnroe 2020-03-09Shorten $HOME to ~ in prompt expansionJune McEnroe 2020-03-09Add PS0 pre-prompt stringJune McEnroe 2020-03-09Add RPS1 and RPS2 right promptsJune McEnroe 2020-03-09Fix copyright and rcsidJune McEnroe 2020-03-09Replace strchrnul with strchrJune McEnroe 2020-03-09Replace eaccess with faccessatJune McEnroe 2020-03-09Replace st_mtim with st_mtimespecJune McEnroe 2020-03-09Replace sys_nsig with NSIGJune McEnroe 2020-03-09Replace 1sh MakefileJune McEnroe 2020-03-09Rename manual pages to 1shJune McEnroe 2020-03-09Move bltin out of subdirectoryJune McEnroe 2020-03-09Import /usr/src/usr.bin/printf from FreeBSD 12.1-RELEASEJune McEnroe 2020-03-09Import /usr/src/bin/test from FreeBSD 12.1-RELEASEJune McEnroe 2020-03-09Import /usr/src/bin/kill from FreeBSD 12.1-RELEASEJune McEnroe 2020-03-09Remove extraneous files from sh sourcesJune McEnroe 2020-03-09Import /usr/src/bin/sh from FreeBSD 12.1-RELEASEJune McEnroe 2020-03-09Remove 1sh sourcesJune McEnroe 2020-03-08Add The Stone SkyJune McEnroe 2020-03-08Publish "How I Relay Chat"June McEnroe 2020-03-03Don't use $ inside $(())June McEnroe 2020-03-03Remove setoptJune McEnroe 2020-03-03Use getopts in shell scriptsJune McEnroe 2020-02-27Style %T outside of Rs in italicJune McEnroe 2020-02-26Add Fierce Femmes and Notorious LiarsJune McEnroe 2020-02-23Add This Is How You Lose the Time WarJune McEnroe 2020-02-22Add See Ya LaterJune McEnroe 2020-02-20Remove wiki scriptJune McEnroe 2020-02-19Add The Obelisk GateJune McEnroe 2020-02-17Add Four Tet — HandsJune McEnroe 2020-02-12Simplify macOS notify-sendJune McEnroe 2020-02-12Add imbox and notemap to pageJune McEnroe 2020-02-12Collapse simple linksJune McEnroe 2020-02-12Move catgirl up the pageJune McEnroe 2020-02-12Update catgirl pty grabJune McEnroe 2020-02-12Link to cgit /about pages where appropriateJune McEnroe 2020-02-11Separate LINKS from BINS for html to workJune McEnroe 2020-02-11Add margin to Bl-bullet itemsJune McEnroe 2020-02-10Match URLs inside parens or with paired parens insideJune McEnroe 2020-02-10Duplicate effective URL before passing it back to curlJune McEnroe 2020-02-09Add To Be Taught, If FortunateJune McEnroe 2020-02-04Add The Future of Another TimelineJune McEnroe 2020-01-31Reorganize the Makefile for the umpteenth timeJune McEnroe 2020-01-28Change scout sensitivity to 1.4June McEnroe 2020-01-28Import shows.txtJune McEnroe