aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/strace.lua
blob: deb8fb77c0468227aba1d993b3cd853a3e36972a (plain) (blame)
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
-- strace(1) output lexer

local l = require('lexer')
local token, word_match = l.token, l.word_match
local S = lpeg.S

local M = {_NAME = 'strace'}

local ws = token(l.WHITESPACE, l.space^1)
local string = token(l.STRING, l.delimited_range('"', true) + l.delimited_range("'", true))
local number = token(l.NUMBER, l.float + l.integer)
local constant = token(l.CONSTANT, (l.upper + '_') * (l.upper + l.digit + '_')^0)
local syscall = token(l.KEYWORD, l.starts_line(l.word))
local operator = token(l.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}'))
local comment = token(l.COMMENT, l.nested_pair('/*', '*/') + ('(' * (l.alpha + ' ')^1 * ')\n'))
local result = token(l.TYPE, '= ' * l.integer)

M._rules = {
  {'whitespace', ws},
  {'keyword', syscall},
  {'constant', constant},
  {'string', string},
  {'comment', comment},
  {'type', result},
  {'number', number},
  {'operator', operator},
}

M._LEXBYLINE = true

return M