vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

strace.lua

(1112B)


      1 -- Copyright 2017-2025 Marc André Tanner. See LICENSE.
      2 -- strace(1) output lexer
      3 
      4 local lexer = lexer
      5 local S, B = lpeg.S, lpeg.B
      6 
      7 local lex = lexer.new(..., {lex_by_line = true})
      8 
      9 -- Syscall
     10 lex:add_rule('syscall', lex:tag(lexer.FUNCTION, lexer.starts_line(lexer.word)))
     11 
     12 -- Upper case constants
     13 lex:add_rule('constant',
     14 	lex:tag(lexer.CONSTANT, (lexer.upper + '_') * (lexer.upper + lexer.digit + '_')^0))
     15 
     16 -- Single and double quoted strings
     17 local sq_str = lexer.range("'", true)
     18 local dq_str = lexer.range('"', true)
     19 lex:add_rule('string', lex:tag(lexer.STRING, sq_str + dq_str))
     20 
     21 -- Comments and text in parentheses at the line end
     22 local comment = lexer.range('/*', '*/')
     23 local description = lexer.range('(', ')') * lexer.newline
     24 lex:add_rule('comment', lex:tag(lexer.COMMENT, comment + description))
     25 
     26 lex:add_rule('result', lex:tag(lexer.TYPE, B(' = ') * lexer.integer))
     27 lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word))
     28 lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.float + lexer.integer))
     29 lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}')))
     30 
     31 return lex