1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
-- Copyright 2023 Sam Nystrom <sam@samnystrom.dev>
-- 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
|