aboutsummaryrefslogtreecommitdiff
path: root/lightroff.lex
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-06-15 18:29:41 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-06-15 18:29:41 +0200
commitbda0c167e13282185609619c63dd0b12164ae3cf (patch)
tree4e55b1631730bf8dc9f565c3f6863436c0687468 /lightroff.lex
parent4b03365723a61dcad79e6df3052621382702f0b3 (diff)
downloadlightroff-bda0c167e13282185609619c63dd0b12164ae3cf.tar.gz
Rename to lightroff.HEADmaster
Diffstat (limited to 'lightroff.lex')
-rw-r--r--lightroff.lex72
1 files changed, 72 insertions, 0 deletions
diff --git a/lightroff.lex b/lightroff.lex
new file mode 100644
index 0000000..9326415
--- /dev/null
+++ b/lightroff.lex
@@ -0,0 +1,72 @@
+%option noyywrap
+%x NEW
+%x REQ
+%x RAW
+%x ESC
+%x RES
+
+%%
+
+\\ BEGIN(ESC);
+^\n* /* Ignore newlines at beginning of file. */
+\n BEGIN(NEW);
+\<!\[ BEGIN(RAW);
+\<!--.*-->\n* /* Ignore comment. */
+^< printf("."); BEGIN(REQ); /* Beginning of file. */
+\< printf("\\c\n."); BEGIN(REQ);
+. ECHO;
+
+ /* Handle text following newlines. */
+
+<NEW>\n /* Ignore consecutive newlines. */
+<NEW>\\ printf("\n"); BEGIN(ESC);
+<NEW><!\[\n? printf("\n"); BEGIN(RAW);
+<NEW><!--.*--> /* Ignore comment. */
+<NEW>< printf("\n."); BEGIN(REQ);
+<NEW>\. printf("\n\\&."); BEGIN(0);
+<NEW>. printf("\n"); BEGIN(0); REJECT;
+
+ /* Translate request. */
+
+<REQ>\\ BEGIN(RES);
+<REQ>> BEGIN(NEW);
+
+ /* Pass through raw troff code. */
+
+<RAW>\n\]> BEGIN(NEW);
+<RAW>\]> BEGIN(0);
+<RAW>. ECHO;
+
+ /* Escape next character. */
+
+<ESC>\\ printf("\\\\"); BEGIN(0);
+<ESC>< ECHO; BEGIN(0);
+<ESC>. printf("\\"); ECHO; BEGIN(0);
+
+ /* Escape next character within request. */
+
+<RES>\\ printf("\\\\"); BEGIN(REQ);
+<RES>> ECHO; BEGIN(REQ);
+<RES>. printf("\\"); ECHO; BEGIN(REQ);
+
+%%
+
+int
+main()
+{
+ char *st;
+
+ yylex();
+
+ switch (YYSTATE) {
+ case 0: return 0;
+ case NEW: printf("\n"); return 0;
+ case REQ: st = "request"; break;
+ case RAW: st = "raw section"; break;
+ case ESC: st = "escape"; break;
+ case RES: st = "escape (within request)"; break;
+ }
+
+ fprintf(stderr, "%s unfinished\n", st);
+ return 1;
+}