From bda0c167e13282185609619c63dd0b12164ae3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 15 Jun 2022 18:29:41 +0200 Subject: Rename to lightroff. --- .gitignore | 5 +-- Makefile | 12 +++---- README | 48 +++++++++++++-------------- README.l | 62 +++++++++++++++++++++++++++++++++++ README.t | 32 +++++++++--------- README.x | 62 ----------------------------------- lightroff.el | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lightroff.lex | 72 ++++++++++++++++++++++++++++++++++++++++ xroff.el | 103 ---------------------------------------------------------- xroff.lex | 72 ---------------------------------------- 10 files changed, 286 insertions(+), 285 deletions(-) create mode 100644 README.l delete mode 100644 README.x create mode 100644 lightroff.el create mode 100644 lightroff.lex delete mode 100644 xroff.el delete mode 100644 xroff.lex diff --git a/.gitignore b/.gitignore index f22fb6c..75ee7c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *~ lex.yy.c -xroff -xroff.exe +lightroff +lightroff.exe *.pdf *.ps +ws/* diff --git a/Makefile b/Makefile index 9cea09a..e511b22 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ CC = gcc -xroff: lex.yy.c - $(CC) $(CFLAGS) $(LDFLAGS) -o xroff lex.yy.c +lightroff: lex.yy.c + $(CC) $(CFLAGS) $(LDFLAGS) -o lightroff lex.yy.c -lex.yy.c: xroff.lex - flex xroff.lex +lex.yy.c: lightroff.lex + flex lightroff.lex README: README.t README -README.t: README.x - README.t +README.t: README.l + README.t diff --git a/README b/README index 466345a..e5623ce 100644 --- a/README +++ b/README @@ -7,7 +7,7 @@ - Xroff, an alternative troff syntax + Lightroff, an alternative troff syntax John Ankarström @@ -15,24 +15,24 @@ Introduction -Xroff is an alternative syntax for troff, visually inspired -by SGML/XML. It differs from troff’s default syntax in the -following ways: +Lightroff is an alternative syntax for troff, visually in‐ +spired by SGML/XML. It differs from troff’s default syntax +in the following ways: -1. Xroff requests begin with a less‐than sign and end with a - greater‐than sign, e.g., . These symbols may be es‐ - caped with a backslash.* +1. Lightroff requests begin with a less‐than sign and end + with a greater‐than sign, e.g., . These symbols may + be escaped with a backslash.* -2. Xroff requests may be used inline. The following works as - expected: (bold).** +2. Lightroff requests may be used inline. The following + works as expected: (bold).** -3. Xroff ignores empty lines. +3. Lightroff ignores empty lines. 4. Default troff syntax may be used between . The similarities with XML end at the visual level. Unlike -XML, xroff is unstructured and imperative. There is no con‐ -cept of closing tags. +XML, lightroff is unstructured and imperative. There is no +concept of closing tags. Example @@ -56,8 +56,8 @@ Example with a newline and a control character, usually a period or an apostrophe, and end with another new‐ line. - ** Before an inline request, xroff automatically -inserts a \c escape when appropriate. + ** Before an inline request, lightroff automati‐ +cally inserts a \c escape when appropriate. @@ -70,22 +70,22 @@ inserts a \c escape when appropriate. ‐2‐ -Xroff +Lightroff -The program xroff translates xroff source to troff source. +The program lightroff translates lightroff source to troff +source. -Xroff‐mode +Lightroff‐mode -For Emacs users, there is a major mode named xroff‐mode that -provides syntax highlighting for xroff source. To further -improve the writing experience, I also recommend olivetti‐ -mode. +For Emacs users, there is a major mode named lightroff‐mode +that provides syntax highlighting for lightroff source. To +further improve the writing experience, I also recommend +olivetti‐mode. Caveats -Xroff does not treat indented lines specially. As such, in‐ -dentation cannot be used to convey structure. - +Lightroff does not treat indented lines specially. As such, +indentation cannot be used to convey structure. diff --git a/README.l b/README.l new file mode 100644 index 0000000..3c92fa6 --- /dev/null +++ b/README.l @@ -0,0 +1,62 @@ + + + + + + + +\\fI\\$*\\fR<.> +\\f(BI\\$*\\fB<.> +\\f(CW\\$*\\fR<.> +\\f(CB\\$*\\fR<.> + + +, an alternative troff syntax +John Ankarstrm + + + +Introduction + is an alternative syntax for troff, visually inspired by SGML/XML. It differs from troff's default syntax in the following ways: + +Lightroff requests begin with a less-than sign and end with a greater-than sign, e.g., >. These symbols may be escaped with a backslash.* +Lightroff requests may be used inline. The following works as expected: bold)">.** +Lightroff ignores empty lines. +Default troff syntax may be used between and >. + +The similarities with XML end at the visual level. Unlike XML, lightroff is unstructured and imperative. There is no concept of closing tags. + +For comparison, default troff requests begin with a newline and a control character, usually a period or an apostrophe, and end with another newline. + +Before an inline request, automatically inserts a escape when appropriate. + + +Example +\\fB\\$*\\fR<.> + +Example document +John Doe + +Pellentesque dapibus suscipit ligula. Donec posuere augue in quam. +Etiam vel tortor sodales tellus ultricies commodo. Suspendisse +potenti. Aenean in sem ac leo mollis blandit. Donec neque quam, +dignissim in, mollis nec, sagittis eu, wisi. + +Introduction + vel est convallis dignissim. Fusce suscipit, +wisi nec facilisis facilisis, est dui fermentum leo, quis tempor +ligula erat quis odio. Nunc porta vulputate tellus. +]> + + + +The program translates lightroff source to troff source. + + + +For Emacs users, there is a major mode named that provides syntax highlighting for lightroff source. To further improve the writing experience, I also recommend . + + +Caveats +Lightroff does not treat indented lines specially. As such, indentation cannot be used to convey structure. diff --git a/README.t b/README.t index 7bc4f4a..35af93c 100644 --- a/README.t +++ b/README.t @@ -15,7 +15,7 @@ \\f(CB\\$*\\fR\c .. .TL -.bi Xroff +.bi Lightroff , an alternative troff syntax .AU John Ankarstrm @@ -23,32 +23,32 @@ John Ankarstr .SH 1 Introduction .LP -.i Xroff +.i Lightroff is an alternative syntax for troff, visually inspired by SGML/XML. It differs from troff's default syntax in the following ways: .IP 1. 3 -Xroff requests begin with a less-than sign and end with a greater-than sign, e.g., \c +Lightroff requests begin with a less-than sign and end with a greater-than sign, e.g., \c .cw \ \&. These symbols may be escaped with a backslash.* .IP 2. -Xroff requests may be used inline. The following works as expected: \c -.cw "(\bold\)" +Lightroff requests may be used inline. The following works as expected: \c +.cw "(bold)" \&.** .IP 3. -Xroff ignores empty lines. +Lightroff ignores empty lines. .IP 4. Default troff syntax may be used between \c -.cw \ \&. .LP -The similarities with XML end at the visual level. Unlike XML, xroff is unstructured and imperative. There is no concept of closing tags. +The similarities with XML end at the visual level. Unlike XML, lightroff is unstructured and imperative. There is no concept of closing tags. .FS * For comparison, default troff requests begin with a newline and a control character, usually a period or an apostrophe, and end with another newline.\c .FE .FS ** Before an inline request, \c -.cw xroff +.cw lightroff automatically inserts a \c .cw \\\\c escape when appropriate.\c @@ -74,20 +74,20 @@ wisi nec facilisis facilisis, est dui fermentum leo, quis tempor ligula erat quis odio. Nunc porta vulputate tellus. .ec .SH 1 -.cwb Xroff +.cwb Lightroff .PP The program \c -.cw xroff - translates xroff source to troff source. +.cw lightroff + translates lightroff source to troff source. .SH 1 -.cwb Xroff-mode +.cwb Lightroff-mode .PP For Emacs users, there is a major mode named \c -.cw xroff-mode - that provides syntax highlighting for xroff source. To further improve the writing experience, I also recommend \c +.cw lightroff-mode + that provides syntax highlighting for lightroff source. To further improve the writing experience, I also recommend \c .cw olivetti-mode \&. .SH 1 Caveats .LP -Xroff does not treat indented lines specially. As such, indentation cannot be used to convey structure. +Lightroff does not treat indented lines specially. As such, indentation cannot be used to convey structure. diff --git a/README.x b/README.x deleted file mode 100644 index ea6bfc0..0000000 --- a/README.x +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - -\\fI\\$*\\fR<.> -\\f(BI\\$*\\fB<.> -\\f(CW\\$*\\fR<.> -\\f(CB\\$*\\fR<.> - - -, an alternative troff syntax -John Ankarstrm - - - -Introduction - is an alternative syntax for troff, visually inspired by SGML/XML. It differs from troff's default syntax in the following ways: - -Xroff requests begin with a less-than sign and end with a greater-than sign, e.g., >. These symbols may be escaped with a backslash.* -Xroff requests may be used inline. The following works as expected: bold\)">.** -Xroff ignores empty lines. -Default troff syntax may be used between and >. - -The similarities with XML end at the visual level. Unlike XML, xroff is unstructured and imperative. There is no concept of closing tags. - -For comparison, default troff requests begin with a newline and a control character, usually a period or an apostrophe, and end with another newline. - -Before an inline request, automatically inserts a escape when appropriate. - - -Example -\\fB\\$*\\fR<.> - -Example document -John Doe - -Pellentesque dapibus suscipit ligula. Donec posuere augue in quam. -Etiam vel tortor sodales tellus ultricies commodo. Suspendisse -potenti. Aenean in sem ac leo mollis blandit. Donec neque quam, -dignissim in, mollis nec, sagittis eu, wisi. - -Introduction - vel est convallis dignissim. Fusce suscipit, -wisi nec facilisis facilisis, est dui fermentum leo, quis tempor -ligula erat quis odio. Nunc porta vulputate tellus. -]> - - - -The program translates xroff source to troff source. - - - -For Emacs users, there is a major mode named that provides syntax highlighting for xroff source. To further improve the writing experience, I also recommend . - - -Caveats -Xroff does not treat indented lines specially. As such, indentation cannot be used to convey structure. diff --git a/lightroff.el b/lightroff.el new file mode 100644 index 0000000..ca49866 --- /dev/null +++ b/lightroff.el @@ -0,0 +1,103 @@ +;;; lightroff.el --- major mode for lightroff -*- lexical-binding: t; -*- + +;; Copyright (C) 2022 John Ankarström + +;; Author: John Ankarström +;; Created: 10 Jul 2022 +;; Version: 0.1 + +;; Keywords: troff groff +;; URL: http://ankarstrom.se/~john/etc/lightroff + +;; This file is not part of GNU Emacs. + +;; Permission to use, copy, modify and/or distribute this software for +;; any purpose with or without fee is hereby granted. + +;;; Commentary: + +;; Major mode for lightroff, an alternative, XML-like syntax for troff. + +;;; Code: + +(defvar lightroff--request-regexp + (rx "<" + (group (+ (or "\\>" (not (in "> "))))) + (group (* (or "\\>" (not ?>)))) + ">")) + +(defvar lightroff--single-escape-regexp + (rx "\\" any)) + +(defvar lightroff--identifier-escape-regexp + (rx "\\" + (any "FfgkmnOsYZ*$") + (? (any "+-")) + (or (not (any "([+-")) + (seq "(" any any) + (seq "[" (* (not "]")) "]")))) + +(defvar lightroff--parameter-escape-regexp + (rx "\\" + (any "ABbCDHhLlMNoRSVvwXxz") + "'" (* (not "'")) "'")) + +(defconst lightroff-font-lock-keywords + `(;; Comment. + ("" + (0 font-lock-comment-face)) + ;; Request. + (,(concat lightroff--request-regexp) + (1 font-lock-keyword-face keep) + (2 font-lock-string-face keep)) + (,(concat "\\\\" lightroff--request-regexp) + (1 nil t) + (2 nil t)) + ;; Parameter escape (e.g., \l'...'). + (,lightroff--parameter-escape-regexp + (0 lightroff-escape-face)) + (,(concat "\\\\" lightroff--parameter-escape-regexp) + (0 nil t)) + ;; Identifier escape (e.g., \n(PI). + (,lightroff--identifier-escape-regexp + (0 lightroff-escape-face)) + (,(concat "\\\\" lightroff--identifier-escape-regexp) + (0 nil t)) + ;; Single escape (e.g., \%). + (,lightroff--single-escape-regexp + (0 lightroff-escape-face)) + (,(concat "\\\\" lightroff--single-escape-regexp) + (0 nil t)) + ;; Escaped backslash. + (,"\\\\\\\\" + (0 lightroff-escape-face t)))) + +(defface lightroff-escape + '((t (:foreground "gray"))) + "`lightroff-mode' face used to highlight backslash escapes." + :group 'lightroff) +(defvar lightroff-escape-face 'lightroff-escape) + +;;;###autoload +(define-derived-mode lightroff-mode text-mode "Lightroff" + "Major mode for editing documents with lightroff syntax." + ;; A start or end tag by itself on a line separates a paragraph. + ;; This is desirable because SGML discards a newline that appears + ;; immediately after a start tag or immediately before an end tag. + (setq-local paragraph-start "<\\([^>]\\)+>") + (setq-local paragraph-separate "$\\|\\]>") + (setq-local adaptive-fill-regexp "[ \t]*") + ;; (add-hook 'fill-nobreak-predicate 'sgml-fill-nobreak nil t) + ;; (setq-local indent-line-function 'sgml-indent-line) + (setq-local comment-start "") + ;; (setq-local comment-indent-function 'sgml-comment-indent) + ;; (setq-local comment-line-break-function 'sgml-comment-indent-new-line) + (setq-local font-lock-defaults '((lightroff-font-lock-keywords))) + ;; (setq-local font-lock-multiline t) + (setq-local comment-start-skip "\n* /* Ignore comment. */ +^< printf("."); BEGIN(REQ); /* Beginning of file. */ +\< printf("\\c\n."); BEGIN(REQ); +. ECHO; + + /* Handle text following newlines. */ + +\n /* Ignore consecutive newlines. */ +\\ printf("\n"); BEGIN(ESC); + /* Ignore comment. */ +< printf("\n."); BEGIN(REQ); +\. printf("\n\\&."); BEGIN(0); +. printf("\n"); BEGIN(0); REJECT; + + /* Translate request. */ + +\\ BEGIN(RES); +> BEGIN(NEW); + + /* Pass through raw troff code. */ + +\n\]> BEGIN(NEW); +\]> BEGIN(0); +. ECHO; + + /* Escape next character. */ + +\\ printf("\\\\"); BEGIN(0); +< ECHO; BEGIN(0); +. printf("\\"); ECHO; BEGIN(0); + + /* Escape next character within request. */ + +\\ printf("\\\\"); BEGIN(REQ); +> ECHO; BEGIN(REQ); +. 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; +} diff --git a/xroff.el b/xroff.el deleted file mode 100644 index 38272fd..0000000 --- a/xroff.el +++ /dev/null @@ -1,103 +0,0 @@ -;;; xroff.el --- major mode for xroff -*- lexical-binding: t; -*- - -;; Copyright (C) 2022 John Ankarström - -;; Author: John Ankarström -;; Created: 10 Jul 2022 -;; Version: 0.1 - -;; Keywords: troff groff -;; URL: http://ankarstrom.se/~john/etc/xroff - -;; This file is not part of GNU Emacs. - -;; Permission to use, copy, modify and/or distribute this software for -;; any purpose with or without fee is hereby granted. - -;;; Commentary: - -;; Major mode for xroff, an alternative, XML-like syntax for troff. - -;;; Code: - -(defvar xroff--request-regexp - (rx "<" - (group (+ (or "\\>" (not (in "> "))))) - (group (* (or "\\>" (not ?>)))) - ">")) - -(defvar xroff--single-escape-regexp - (rx "\\" any)) - -(defvar xroff--identifier-escape-regexp - (rx "\\" - (any "FfgkmnOsYZ*$") - (? (any "+-")) - (or (not (any "([+-")) - (seq "(" any any) - (seq "[" (* (not "]")) "]")))) - -(defvar xroff--parameter-escape-regexp - (rx "\\" - (any "ABbCDHhLlMNoRSVvwXxz") - "'" (* (not "'")) "'")) - -(defconst xroff-font-lock-keywords - `(;; Comment. - ("" - (0 font-lock-comment-face)) - ;; Request. - (,(concat xroff--request-regexp) - (1 font-lock-keyword-face keep) - (2 font-lock-string-face keep)) - (,(concat "\\\\" xroff--request-regexp) - (1 nil t) - (2 nil t)) - ;; Parameter escape (e.g., \l'...'). - (,xroff--parameter-escape-regexp - (0 xroff-escape-face)) - (,(concat "\\\\" xroff--parameter-escape-regexp) - (0 nil t)) - ;; Identifier escape (e.g., \n(PI). - (,xroff--identifier-escape-regexp - (0 xroff-escape-face)) - (,(concat "\\\\" xroff--identifier-escape-regexp) - (0 nil t)) - ;; Single escape (e.g., \%). - (,xroff--single-escape-regexp - (0 xroff-escape-face)) - (,(concat "\\\\" xroff--single-escape-regexp) - (0 nil t)) - ;; Escaped backslash. - (,"\\\\\\\\" - (0 xroff-escape-face t)))) - -(defface xroff-escape - '((t (:foreground "gray"))) - "`xroff-mode' face used to highlight backslash escapes." - :group 'xroff) -(defvar xroff-escape-face 'xroff-escape) - -;;;###autoload -(define-derived-mode xroff-mode text-mode "Xroff" - "Major mode for editing documents with xroff syntax." - ;; A start or end tag by itself on a line separates a paragraph. - ;; This is desirable because SGML discards a newline that appears - ;; immediately after a start tag or immediately before an end tag. - (setq-local paragraph-start "<\\([^>]\\)+>") - (setq-local paragraph-separate "$\\|\\]>") - (setq-local adaptive-fill-regexp "[ \t]*") - ;; (add-hook 'fill-nobreak-predicate 'sgml-fill-nobreak nil t) - ;; (setq-local indent-line-function 'sgml-indent-line) - (setq-local comment-start "") - ;; (setq-local comment-indent-function 'sgml-comment-indent) - ;; (setq-local comment-line-break-function 'sgml-comment-indent-new-line) - (setq-local font-lock-defaults '((xroff-font-lock-keywords))) - ;; (setq-local font-lock-multiline t) - (setq-local comment-start-skip "\n* /* Ignore comment. */ -^< printf("."); BEGIN(REQ); /* Beginning of file. */ -\< printf("\\c\n."); BEGIN(REQ); -. ECHO; - - /* Handle text following newlines. */ - -\n /* Ignore consecutive newlines. */ -\\ printf("\n"); BEGIN(ESC); - /* Ignore comment. */ -< printf("\n."); BEGIN(REQ); -\. printf("\n\\&."); BEGIN(0); -. printf("\n"); BEGIN(0); REJECT; - - /* Translate request. */ - -\\ BEGIN(RES); -> BEGIN(NEW); - - /* Pass through raw troff code. */ - -\n\]> BEGIN(NEW); -\]> BEGIN(0); -. ECHO; - - /* Escape next character. */ - -\\ printf("\\\\"); BEGIN(0); -< ECHO; BEGIN(0); -. printf("\\"); ECHO; BEGIN(0); - - /* Escape next character within request. */ - -\\ printf("\\\\"); BEGIN(REQ); -> ECHO; BEGIN(REQ); -. 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; -} -- cgit v1.2.3