1 -- Copyright 2006-2013 Robert Gieseke. See LICENSE.
4 local l
= require('lexer')
5 local token
, word_match
= l
.token
, l
.word_match
6 local P
, R
, S
= lpeg
.P
, lpeg
.R
, lpeg
.S
8 local M
= {_NAME
= 'context'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local comment
= token(l
.COMMENT
, '%' * l
.nonnewline^
0)
17 local command
= token(l
.KEYWORD
, '\\' * (l
.alpha^
1 + S('#$&~_^%{}')))
20 local section
= token('section', '\\' * word_match
{
21 'part', 'chapter', 'section', 'subsection', 'subsubsection', 'title',
22 'subject', 'subsubject', 'subsubsubject'
25 -- ConTeXt environments.
26 local environment
= token('environment', '\\' * (P('start') + 'stop') * l
.word
)
29 local operator
= token(l
.OPERATOR
, S('$&#{}[]'))
34 {'environment', environment
},
37 {'operator', operator
},
41 environment
= l
.STYLE_KEYWORD
,
42 section
= l
.STYLE_CLASS
46 _patterns
= {'\\start', '\\stop', '[{}]', '%%'},
47 ['environment'] = {['\\start'] = 1, ['\\stop'] = -1},
48 [l
.OPERATOR
] = {['{'] = 1, ['}'] = -1},
49 [l
.COMMENT
] = {['%'] = l
.fold_line_comments('%')}
53 local luatex
= l
.load('lua')
54 local luatex_start_rule
= #P('\\startluacode') * environment
55 local luatex_end_rule
= #P('\\stopluacode') * environment
56 l
.embed_lexer(M
, luatex
, luatex_start_rule
, luatex_end_rule
)