File: strace.lua

package info (click to toggle)
vis 0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,624 kB
  • sloc: ansic: 23,195; sh: 981; makefile: 363; python: 47
file content (31 lines) | stat: -rw-r--r-- 1,113 bytes parent folder | download
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
-- Copyright 2017-2024 Marc André Tanner. See LICENSE.
-- strace(1) output lexer

local lexer = lexer
local S, B = lpeg.S, lpeg.B

local lex = lexer.new(..., {lex_by_line = true})

-- Syscall
lex:add_rule('syscall', lex:tag(lexer.FUNCTION, lexer.starts_line(lexer.word)))

-- Upper case constants
lex:add_rule('constant',
  lex:tag(lexer.CONSTANT, (lexer.upper + '_') * (lexer.upper + lexer.digit + '_')^0))

-- Single and double quoted strings
local sq_str = lexer.range("'", true)
local dq_str = lexer.range('"', true)
lex:add_rule('string', lex:tag(lexer.STRING, sq_str + dq_str))

-- Comments and text in parentheses at the line end
local comment = lexer.range('/*', '*/')
local description = lexer.range('(', ')') * lexer.newline
lex:add_rule('comment', lex:tag(lexer.COMMENT, comment + description))

lex:add_rule('result', lex:tag(lexer.TYPE, B(' = ') * lexer.integer))
lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word))
lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.float + lexer.integer))
lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}')))

return lex