diff options
| author | mitchell <unknown> | 2020-04-25 16:26:31 -0400 |
|---|---|---|
| committer | mitchell <unknown> | 2020-04-25 16:26:31 -0400 |
| commit | fad15f79b1230b3076be515d6894c8919562809b (patch) | |
| tree | 72c848ef02c3331de5ca54eff7adaea3a9a6fb88 /lexlua/context.lua | |
| parent | 1fd02a367dec125c0b49dd9246a0928433866b96 (diff) | |
| download | scintilla-mirror-fad15f79b1230b3076be515d6894c8919562809b.tar.gz | |
Reformatted Lua LPeg lexers and added new convenience functions and pattern.
`lexer.range()` replaces `lexer.delimited_range()` and `lexer.nested_pair()`.
`lexer.to_eol()` replaces `patt * lexer.nonnewline^0` constructs.
`lexer.number` replaces `lexer.float + lexer.integer`.
Also added unit tests for lexer functions.
Diffstat (limited to 'lexlua/context.lua')
| -rw-r--r-- | lexlua/context.lua | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/lexlua/context.lua b/lexlua/context.lua index 87811164b..904354c55 100644 --- a/lexlua/context.lua +++ b/lexlua/context.lua @@ -12,32 +12,31 @@ local beginend = (P('begin') + 'end') local startstop = (P('start') + 'stop') -- Whitespace. -local ws = token(lexer.WHITESPACE, lexer.space^1) -lex:add_rule('whitespace', ws) +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Comments. -local comment = token(lexer.COMMENT, '%' * lexer.nonnewline^0) -lex:add_rule('comment', comment) +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('%'))) -- Sections. local wm_section = word_match[[ chapter part section subject subsection subsubject subsubsection subsubsubject subsubsubsection subsubsubsubject title ]] -local section = token(lexer.CLASS, - '\\' * (wm_section + (startstop * wm_section))) +local section = token(lexer.CLASS, '\\' * + (wm_section + (startstop * wm_section))) lex:add_rule('section', section) -- TeX and ConTeXt mkiv environments. -local environment = token(lexer.STRING, - '\\' * (beginend + startstop) * lexer.alpha^1) +local environment = token(lexer.STRING, '\\' * (beginend + startstop) * + lexer.alpha^1) lex:add_rule('environment', environment) -- Commands. -local command = token(lexer.KEYWORD, - '\\' * (lexer.alpha^1 * P('\\') * lexer.space^1 + - lexer.alpha^1 + - S('!"#$%&\',./;=[\\]_{|}~`^-'))) +local command = token(lexer.KEYWORD, '\\' * ( + lexer.alpha^1 * P('\\') * lexer.space^1 + + lexer.alpha^1 + + S('!"#$%&\',./;=[\\]_{|}~`^-') +)) lex:add_rule('command', command) -- Operators. |
