diff options
Diffstat (limited to 'lua/lexers/strace.lua')
| -rw-r--r-- | lua/lexers/strace.lua | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/lua/lexers/strace.lua b/lua/lexers/strace.lua index 3547dd2..846c4fc 100644 --- a/lua/lexers/strace.lua +++ b/lua/lexers/strace.lua @@ -1,34 +1,35 @@ -- 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 lexer = require('lexer') +local token, word_match = lexer.token, lexer.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 +local lex = lexer.new('strace', {lex_by_line = true}) + +-- Whitespace +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Syscall +lex:add_rule('syscall', token(lexer.KEYWORD, lexer.starts_line(lexer.word))) + +-- Upper case constants +lex:add_rule('constant', token(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', token(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', token(lexer.COMMENT, comment + description)) + +lex:add_rule('result', token(lexer.TYPE, B(' = ') * lexer.integer)) +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) +lex:add_rule('number', token(lexer.NUMBER, lexer.float + lexer.integer)) +lex:add_rule('operator', token(lexer.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}'))) + +return lex |
