-- Copyright 2023 Sam Nystrom -- 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 = 'roff'} -- Whitespace local ws = token(l.WHITESPACE, l.space^1) -- Comments local comment = token(l.COMMENT, '\\"' * l.nonnewline^0) -- Strings local string = token(l.STRING, l.delimited_range('"')) -- Keywords local word = (l.alpha + '_') * (l.alnum + S('_.'))^0 local keyword = token(l.KEYWORD, l.starts_line('.') * l.word) M._rules = { {'whitespace', ws}, {'keyword', keyword}, {'string', string}, {'comment', comment}, } M._LEXBYLINE = true return M