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/ini.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lexlua/ini.lua') diff --git a/lexlua/ini.lua b/lexlua/ini.lua index d5445ba12..d56539d42 100644 --- a/lexlua/ini.lua +++ b/lexlua/ini.lua @@ -17,19 +17,19 @@ lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * - (lexer.alnum + S('_.'))^0)) + (lexer.alnum + S('_.'))^0)) -- Strings. -lex:add_rule('string', token(lexer.STRING, lexer.delimited_range("'") + - lexer.delimited_range('"'))) +local sq_str = lexer.range("'") +local dq_str = lexer.range('"') +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) -- Labels. -lex:add_rule('label', token(lexer.LABEL, - lexer.delimited_range('[]', true, true))) +lex:add_rule('label', token(lexer.LABEL, lexer.range('[', ']', true))) -- Comments. -lex:add_rule('comment', token(lexer.COMMENT, lexer.starts_line(S(';#')) * - lexer.nonnewline^0)) +lex:add_rule('comment', token(lexer.COMMENT, + lexer.to_eol(lexer.starts_line(S(';#'))))) -- Numbers. local dec = lexer.digit^1 * ('_' * lexer.digit^1)^0 -- cgit v1.2.3