logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

troff.lua (1823B)


  1. -- Copyright 2023-2024 Mitchell. See LICENSE.
  2. -- troff/man LPeg lexer.
  3. -- Based on original Man lexer by David B. Lamkins and modified by Eolien55.
  4. local lexer = lexer
  5. local P, R, S = lpeg.P, lpeg.R, lpeg.S
  6. local lex = lexer.new(...)
  7. -- Registers and groff's structured programming.
  8. lex:add_rule('keywords', lex:tag(lexer.KEYWORD, (lexer.starts_line('.') * (lexer.space - '\n')^0 *
  9. (P('while') + 'break' + 'continue' + 'nr' + 'rr' + 'rnn' + 'aln' + '\\}')) + '\\{'))
  10. -- Markup.
  11. lex:add_rule('escape_sequences', lex:tag(lexer.VARIABLE,
  12. '\\' * (('s' * S('+-')^-1) + S('*fgmnYV'))^-1 * (P('(') * 2 + lexer.range('[', ']') + 1)))
  13. lex:add_rule('headings', lex:tag(lexer.NUMBER,
  14. lexer.starts_line('.') * (lexer.space - '\n')^0 * (S('STN') * 'H') * (lexer.space - '\n') *
  15. lexer.nonnewline^0))
  16. lex:add_rule('man_alignment', lex:tag(lexer.KEYWORD,
  17. lexer.starts_line('.') * (lexer.space - '\n')^0 * (P('br') + 'DS' + 'RS' + 'RE' + 'PD' + 'PP') *
  18. lexer.space))
  19. lex:add_rule('font', lex:tag(lexer.VARIABLE,
  20. lexer.starts_line('.') * (lexer.space - '\n')^0 * ('B' * P('R')^-1 + 'I' * S('PR')^-1) *
  21. lexer.space))
  22. -- Lowercase troff macros are plain macros (like .so or .nr).
  23. lex:add_rule('troff_plain_macros', lex:tag(lexer.VARIABLE, lexer.starts_line('.') *
  24. (lexer.space - '\n')^0 * lexer.lower^1))
  25. lex:add_rule('any_macro', lex:tag(lexer.PREPROCESSOR,
  26. lexer.starts_line('.') * (lexer.space - '\n')^0 * (lexer.any - lexer.space)^0))
  27. lex:add_rule('comment', lex:tag(lexer.COMMENT,
  28. (lexer.starts_line('.\\"') + '\\"' + '\\#') * lexer.nonnewline^0))
  29. lex:add_rule('string', lex:tag(lexer.STRING, lexer.range('"', true)))
  30. -- Usually used by eqn, and mandoc in some way.
  31. lex:add_rule('in_dollars', lex:tag(lexer.EMBEDDED, lexer.range('$', false, false)))
  32. -- TODO: a lexer for each preprocessor?
  33. return lex