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/autoit.lua | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'lexlua/autoit.lua') diff --git a/lexlua/autoit.lua b/lexlua/autoit.lua index 5bb5752f9..3b6d3ae6a 100644 --- a/lexlua/autoit.lua +++ b/lexlua/autoit.lua @@ -97,12 +97,10 @@ lex:add_rule('function', token(lexer.FUNCTION, word_match([[ lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- Comments. -local line_comment = ';' * lexer.nonnewline_esc^0 -local block_comment1 = '#comments-start' * (lexer.any - '#comments-end')^0 * - P('#comments-end')^-1 -local block_comment2 = '#cs' * (lexer.any - '#ce')^0 * P('#ce')^-1 -lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment1 + - block_comment2)) +local line_comment = lexer.to_eol(';') +local block_comment = lexer.range('#comments-start', '#comments-end') + + lexer.range('#cs', '#ce') +lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Preprocessor. lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, '#' * word_match([[ @@ -111,9 +109,9 @@ lex:add_rule('preprocessor', token(lexer.PREPROCESSOR, '#' * word_match([[ ]], true))) -- Strings. -local dq_str = lexer.delimited_range('"', true, true) -local sq_str = lexer.delimited_range("'", true, true) -local inc = lexer.delimited_range('<>', true, true, true) +local dq_str = lexer.range('"', true, false) +local sq_str = lexer.range("'", true, false) +local inc = lexer.range('<', '>', true, false, true) lex:add_rule('string', token(lexer.STRING, dq_str + sq_str + inc)) -- Macros. @@ -124,7 +122,7 @@ lex:add_style('macro', lexer.STYLE_PREPROCESSOR) lex:add_rule('variable', token(lexer.VARIABLE, '$' * (lexer.alnum + '_')^1)) -- Numbers. -lex:add_rule('number', token(lexer.NUMBER, lexer.float + lexer.integer)) +lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('+-^*/&<>=?:()[]'))) -- cgit v1.2.3