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/apdl.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lexlua/apdl.lua') diff --git a/lexlua/apdl.lua b/lexlua/apdl.lua index 22dc64b83..be70f2a5d 100644 --- a/lexlua/apdl.lua +++ b/lexlua/apdl.lua @@ -46,21 +46,19 @@ lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- Strings. -lex:add_rule('string', token(lexer.STRING, - lexer.delimited_range("'", true, true))) +lex:add_rule('string', token(lexer.STRING, lexer.range("'", true, false))) -- Numbers. -lex:add_rule('number', token(lexer.NUMBER, lexer.float + lexer.integer)) +lex:add_rule('number', token(lexer.NUMBER, lexer.number)) -- Functions. -lex:add_rule('function', token(lexer.FUNCTION, - lexer.delimited_range('%', true, true))) +lex:add_rule('function', token(lexer.FUNCTION, lexer.range('%', true, false))) -- Labels. lex:add_rule('label', token(lexer.LABEL, lexer.starts_line(':') * lexer.word)) -- Comments. -lex:add_rule('comment', token(lexer.COMMENT, '!' * lexer.nonnewline^0)) +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('!'))) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('+-*/$=,;()'))) -- cgit v1.2.3