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/apl.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lexlua/apl.lua') diff --git a/lexlua/apl.lua b/lexlua/apl.lua index 285ae0737..ad0ec2d99 100644 --- a/lexlua/apl.lua +++ b/lexlua/apl.lua @@ -12,11 +12,11 @@ lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Comments. lex:add_rule('comment', token(lexer.COMMENT, (P('⍝') + '#') * - lexer.nonnewline^0)) + lexer.nonnewline^0)) -- Strings. -local sq_str = lexer.delimited_range("'", false, true) -local dq_str = lexer.delimited_range('"') +local sq_str = lexer.range("'", false, false) +local dq_str = lexer.range('"') lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) -- Numbers. @@ -26,12 +26,12 @@ local exp = S('eE') local img = S('jJ') local sgn = P('¯')^-1 local float = sgn * (dig^0 * rad * dig^1 + dig^1 * rad * dig^0 + dig^1) * - (exp * sgn *dig^1)^-1 + (exp * sgn *dig^1)^-1 lex:add_rule('number', token(lexer.NUMBER, float * img * float + float)) -- Keywords. lex:add_rule('keyword', token(lexer.KEYWORD, P('⍞') + 'χ' + '⍺' + '⍶' + '⍵' + - '⍹' + '⎕' * R('AZ', 'az')^0)) + '⍹' + '⎕' * R('AZ', 'az')^0)) -- Names. local n1l = R('AZ', 'az') -- cgit v1.2.3