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/icon.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lexlua/icon.lua') diff --git a/lexlua/icon.lua b/lexlua/icon.lua index 08a4e3f62..a850f03a1 100644 --- a/lexlua/icon.lua +++ b/lexlua/icon.lua @@ -32,16 +32,16 @@ lex:add_style('special_keyword', lexer.STYLE_TYPE) lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- 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)) -- Comments. -lex:add_rule('comment', token(lexer.COMMENT, '#' * lexer.nonnewline_esc^0)) +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#', true))) -- Numbers. local radix_literal = P('-')^-1 * lexer.dec_num * S('rR') * lexer.alnum^1 -lex:add_rule('number', token(lexer.NUMBER, radix_literal + lexer.float + - lexer.integer)) +lex:add_rule('number', token(lexer.NUMBER, radix_literal + lexer.number)) -- Preprocessor. local preproc_word = word_match[[ -- cgit v1.2.3