vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit b55e990e33c7eef68ae351529a77b36d7a31cf3e parent 2bcb892484612beaa74429f8d3c2abee0af4d04e Author: David B. Lamkins <dlamkins@galois.com> Date: Sat, 31 Oct 2015 19:14:48 +0100 lexer: new lexer for man/roff format Diffstat:
| M | lexers/lexer.lua | | | 1 | + |
| A | lexers/man.lua | | | 35 | +++++++++++++++++++++++++++++++++++ |
2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/lexers/lexer.lua b/lexers/lexer.lua @@ -1595,6 +1595,7 @@ function M.get_style(lexer, lang, token_name) end local files = { + [".1|.2|.3|.4|.5|.6|.7|.8|.9|.1x|.2x|.3x|.4x|.5x|.6x|.7x|.8x|.9x"] = "man", [".as|.asc"] = "actionscript", [".adb|.ads"] = "ada", [".g|.g4"] = "antlr", diff --git a/lexers/man.lua b/lexers/man.lua @@ -0,0 +1,35 @@ +-- man/roff LPeg lexer. + +local l = require('lexer') +local token, word_match = l.token, l.word_match +local P, R, S = lpeg.P, lpeg.R, lpeg.S + +local M = {_NAME = 'man'} + +-- Whitespace. +local ws = token(l.WHITESPACE, l.space^1) + +-- Markup. +local rule1 = token(l.STRING, + P('.') * (P('B') * P('R')^-1 + P('I') * P('PR')^-1) * l.nonnewline^0) +local rule2 = token(l.NUMBER, P('.') * S('ST') * P('H') * l.nonnewline^0) +local rule3 = token(l.KEYWORD, + P('.br') + P('.DS') + P('.RS') + P('.RE') + P('.PD')) +local rule4 = token(l.LABEL, P('.') * (S('ST') * P('H') + P('.TP'))) +local rule5 = token(l.VARIABLE, + P('.B') * P('R')^-1 + P('.I') * S('PR')^-1 + P('.PP')) +local rule6 = token(l.TYPE, P('\\f') * S('BIPR')) +local rule7 = token(l.PREPROCESSOR, l.starts_line('.') * l.alpha^1) + +M._rules = { + {'whitespace', ws}, + {'rule1', rule1}, + {'rule2', rule2}, + {'rule3', rule3}, + {'rule4', rule4}, + {'rule5', rule5}, + {'rule6', rule6}, + {'rule7', rule7}, +} + +return M