diff options
| author | mitchell <unknown> | 2020-04-25 16:26:31 -0400 |
|---|---|---|
| committer | mitchell <unknown> | 2020-04-25 16:26:31 -0400 |
| commit | fad15f79b1230b3076be515d6894c8919562809b (patch) | |
| tree | 72c848ef02c3331de5ca54eff7adaea3a9a6fb88 /lexlua/nim.lua | |
| parent | 1fd02a367dec125c0b49dd9246a0928433866b96 (diff) | |
| download | scintilla-mirror-fad15f79b1230b3076be515d6894c8919562809b.tar.gz | |
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.
Diffstat (limited to 'lexlua/nim.lua')
| -rw-r--r-- | lexlua/nim.lua | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/lexlua/nim.lua b/lexlua/nim.lua index 203ed3628..8840aa8fc 100644 --- a/lexlua/nim.lua +++ b/lexlua/nim.lua @@ -69,18 +69,17 @@ lex:add_rule('constant', token(lexer.CONSTANT, word_match[[ ]])) -- Strings. -local sq_str = lexer.delimited_range("'", true) -local dq_str = lexer.delimited_range('"', true) -local triple_dq_str = '"""' * (lexer.any - '"""')^0 * P('"""')^-1 -local raw_dq_str = 'r' * lexer.delimited_range('"', false, true) -lex:add_rule('string', token(lexer.STRING, triple_dq_str + sq_str + dq_str + - raw_dq_str)) +local sq_str = lexer.range("'", true) +local dq_str = lexer.range('"', true) +local tq_str = lexer.range('"""') +local raw_str = 'r' * lexer.range('"', false, false) +lex:add_rule('string', token(lexer.STRING, tq_str + sq_str + dq_str + raw_str)) -- Identifiers. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) -- 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 dec = lexer.digit^1 * ('_' * lexer.digit^1)^0 @@ -88,14 +87,14 @@ local hex = '0' * S('xX') * lexer.xdigit^1 * ('_' * lexer.xdigit^1)^0 local bin = '0' * S('bB') * S('01')^1 * ('_' * S('01')^1)^0 local oct = '0o' * R('07')^1 local integer = S('+-')^-1 * (bin + hex + oct + dec) * - ("'" * S('iIuUfF') * (P('8') + '16' + '32' + '64'))^-1 + ("'" * S('iIuUfF') * (P('8') + '16' + '32' + '64'))^-1 local float = lexer.digit^1 * ('_' * lexer.digit^1)^0 * - ('.' * ('_' * lexer.digit)^0)^-1 * S('eE') * S('+-')^-1 * - lexer.digit^1 * ('_' * lexer.digit^1)^0 + ('.' * ('_' * lexer.digit)^0)^-1 * S('eE') * S('+-')^-1 * lexer.digit^1 * + ('_' * lexer.digit^1)^0 lex:add_rule('number', token(lexer.NUMBER, lexer.float + integer)) -- Operators. lex:add_rule('operator', token(lexer.OPERATOR, - S('=+-*/<>@$~&%|!?^.:\\`()[]{},;'))) + S('=+-*/<>@$~&%|!?^.:\\`()[]{},;'))) return lex |
