logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

latex.lua (1507B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Latex LPeg lexer.
  3. -- Modified by Brian Schott.
  4. -- Modified by Robert Gieseke.
  5. local lexer = lexer
  6. local word_match = lexer.word_match
  7. local P, S = lpeg.P, lpeg.S
  8. local lex = lexer.new(...)
  9. -- Comments.
  10. local line_comment = lexer.to_eol('%')
  11. local block_comment = lexer.range('\\begin' * P(' ')^0 * '{comment}',
  12. '\\end' * P(' ')^0 * '{comment}')
  13. lex:add_rule('comment', lex:tag(lexer.COMMENT, line_comment + block_comment))
  14. -- Math environments.
  15. local math_word = word_match('align displaymath eqnarray equation gather math multline')
  16. local math_begin_end = (P('begin') + P('end')) * P(' ')^0 * '{' * math_word * P('*')^-1 * '}'
  17. lex:add_rule('math', lex:tag('environment.math', '$' + '\\' * (S('[]()') + math_begin_end)))
  18. -- LaTeX environments.
  19. lex:add_rule('environment', lex:tag('environment', '\\' * (P('begin') + 'end') * P(' ')^0 * '{' *
  20. lexer.word * P('*')^-1 * '}'))
  21. -- Sections.
  22. lex:add_rule('section', lex:tag('command.section', '\\' *
  23. word_match('part chapter section subsection subsubsection paragraph subparagraph') * P('*')^-1))
  24. -- Commands.
  25. lex:add_rule('command', lex:tag('command', '\\' * (lexer.alpha^1 + S('#$&~_^%{}\\'))))
  26. -- Operators.
  27. lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('&#{}[]')))
  28. -- Fold points.
  29. lex:add_fold_point(lexer.COMMENT, '\\begin', '\\end')
  30. lex:add_fold_point('environment', '\\begin', '\\end')
  31. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  32. lexer.property['scintillua.comment'] = '%'
  33. return lex