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

context.lua (1739B)


  1. -- Copyright 2006-2024 Robert Gieseke, Lars Otter. See LICENSE.
  2. -- ConTeXt LPeg lexer.
  3. local lexer = require('lexer')
  4. local token, word_match = lexer.token, lexer.word_match
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new('context')
  7. -- TeX and ConTeXt mkiv environment definitions.
  8. local beginend = (P('begin') + 'end')
  9. local startstop = (P('start') + 'stop')
  10. -- Whitespace.
  11. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  12. -- Comments.
  13. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('%')))
  14. -- Sections.
  15. local wm_section = word_match{
  16. 'chapter', 'part', 'section', 'subject', 'subsection', 'subsubject', 'subsubsection',
  17. 'subsubsubject', 'subsubsubsection', 'subsubsubsubject', 'title'
  18. }
  19. local section = token(lexer.CLASS, '\\' * startstop^-1 * wm_section)
  20. lex:add_rule('section', section)
  21. -- TeX and ConTeXt mkiv environments.
  22. local environment = token(lexer.STRING, '\\' * (beginend + startstop) * lexer.alpha^1)
  23. lex:add_rule('environment', environment)
  24. -- Commands.
  25. local command = token(lexer.KEYWORD, '\\' *
  26. (lexer.alpha^1 * P('\\') * lexer.space^1 + lexer.alpha^1 + S('!"#$%&\',./;=[\\]_{|}~`^-')))
  27. lex:add_rule('command', command)
  28. -- Operators.
  29. local operator = token(lexer.OPERATOR, S('#$_[]{}~^'))
  30. lex:add_rule('operator', operator)
  31. -- Fold points.
  32. lex:add_fold_point('environment', '\\start', '\\stop')
  33. lex:add_fold_point('environment', '\\begin', '\\end')
  34. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  35. -- Embedded Lua.
  36. local luatex = lexer.load('lua')
  37. local luatex_start_rule = #P('\\startluacode') * environment
  38. local luatex_end_rule = #P('\\stopluacode') * environment
  39. lex:embed(luatex, luatex_start_rule, luatex_end_rule)
  40. lexer.property['scintillua.comment'] = '%'
  41. return lex