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/erlang.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lexlua/erlang.lua') diff --git a/lexlua/erlang.lua b/lexlua/erlang.lua index 943e31b36..0d2a3b19b 100644 --- a/lexlua/erlang.lua +++ b/lexlua/erlang.lua @@ -42,11 +42,11 @@ lex:add_rule('function', token(lexer.FUNCTION, word_match[[ -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.lower * - ('_' + lexer.alnum)^0)) + ('_' + lexer.alnum)^0)) -- Variables. lex:add_rule('variable', token(lexer.VARIABLE, P('_')^0 * lexer.upper * - ('_' + lexer.alnum)^0)) + ('_' + lexer.alnum)^0)) -- Directives. lex:add_rule('directive', token('directive', '-' * word_match[[ @@ -56,15 +56,16 @@ lex:add_rule('directive', token('directive', '-' * word_match[[ lex:add_style('directive', lexer.STYLE_PREPROCESSOR) -- Strings. -lex:add_rule('string', token(lexer.STRING, lexer.delimited_range("'", true) + - lexer.delimited_range('"') + - '$' * lexer.any * lexer.alnum^0)) +local sq_str = lexer.range("'", true) +local dq_str = lexer.range('"') +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + + '$' * lexer.any * lexer.alnum^0)) -- Comments. -lex:add_rule('comment', token(lexer.COMMENT, '%' * lexer.nonnewline^0)) +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('%'))) -- 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