From fad15f79b1230b3076be515d6894c8919562809b Mon Sep 17 00:00:00 2001 From: mitchell Date: Sat, 25 Apr 2020 16:26:31 -0400 Subject: 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. --- lexlua/context.lua | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'lexlua/context.lua') 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. -- cgit v1.2.3