vis

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

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

tex.lua

(726B)


      1 -- Copyright 2006-2025 Mitchell. See LICENSE.
      2 -- Plain TeX LPeg lexer.
      3 -- Modified by Robert Gieseke.
      4 
      5 local lexer = lexer
      6 local P, S = lpeg.P, lpeg.S
      7 
      8 local lex = lexer.new(...)
      9 
     10 -- Comments.
     11 lex:add_rule('comment', lex:tag(lexer.COMMENT, lexer.to_eol('%')))
     12 
     13 -- TeX environments.
     14 lex:add_rule('environment', lex:tag('environment', '\\' * (P('begin') + 'end') * lexer.word))
     15 
     16 -- Commands.
     17 lex:add_rule('command', lex:tag('command', '\\' * (lexer.alpha^1 + S('#$&~_^%{}'))))
     18 
     19 -- Operators.
     20 lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('$&#{}[]')))
     21 
     22 -- Fold points.
     23 lex:add_fold_point('environment', '\\begin', '\\end')
     24 lex:add_fold_point(lexer.OPERATOR, '{', '}')
     25 
     26 lexer.property['scintillua.comment'] = '%'
     27 
     28 return lex