aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/strace.lua
blob: 3547dd230e96c8f42b58e94c618536d26e7e0520 (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
32
33
34
-- Copyright 2017-2021 Marc André Tanner. See LICENSE.
-- strace(1) output lexer

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

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.delimited_range('()') * l.newline))
local result = token(l.TYPE, B(' = ') * l.integer)
local identifier = token(l.IDENTIFIER, l.word)

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

M._LEXBYLINE = true

return M