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/rebol.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lexlua/rebol.lua') diff --git a/lexlua/rebol.lua b/lexlua/rebol.lua index 7cc8a2186..5994a4cd5 100644 --- a/lexlua/rebol.lua +++ b/lexlua/rebol.lua @@ -11,9 +11,8 @@ local lex = lexer.new('rebol') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Comments. -local line_comment = ';' * lexer.nonnewline^0; -local block_comment = 'comment' * P(' ')^-1 * - lexer.delimited_range('{}', false, true) +local line_comment = lexer.to_eol(';') +local block_comment = 'comment' * P(' ')^-1 * lexer.range('{', '}') lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment)) -- Keywords. @@ -80,12 +79,13 @@ lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '-') * - (lexer.alnum + '-')^0)) + (lexer.alnum + '-')^0)) -- Strings. -lex:add_rule('string', token(lexer.STRING, lexer.delimited_range('"', true) + - lexer.delimited_range('{}') + - "'" * lexer.word)) +local dq_str = lexer.range('"', true) +local br_str = lexer.range('{', '}', false, false, true) +local word_str = "'" * lexer.word +lex:add_rule('string', token(lexer.STRING, dq_str + br_str + word_str)) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, S('=<>+/*:()[]'))) -- cgit v1.2.3