aboutsummaryrefslogtreecommitdiffhomepage
path: root/lexlua/lua.lua
diff options
context:
space:
mode:
authormitchell <unknown>2020-04-25 16:26:31 -0400
committermitchell <unknown>2020-04-25 16:26:31 -0400
commitfad15f79b1230b3076be515d6894c8919562809b (patch)
tree72c848ef02c3331de5ca54eff7adaea3a9a6fb88 /lexlua/lua.lua
parent1fd02a367dec125c0b49dd9246a0928433866b96 (diff)
downloadscintilla-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/lua.lua')
-rw-r--r--lexlua/lua.lua26
1 files changed, 14 insertions, 12 deletions
diff --git a/lexlua/lua.lua b/lexlua/lua.lua
index c648475ef..655f237f5 100644
--- a/lexlua/lua.lua
+++ b/lexlua/lua.lua
@@ -32,7 +32,7 @@ local deprecated_func = token('deprecated_function', word_match[[
getfenv loadstring module setfenv unpack
]])
lex:add_rule('function', func + deprecated_func)
-lex:add_style('deprecated_function', lexer.STYLE_FUNCTION..',italics')
+lex:add_style('deprecated_function', lexer.STYLE_FUNCTION .. ',italics')
-- Constants.
lex:add_rule('constant', token(lexer.CONSTANT, word_match[[
@@ -103,26 +103,28 @@ local deprecated_library = token('deprecated_library', word_match[[
]])
lex:add_rule('library', library + deprecated_library)
lex:add_style('library', lexer.STYLE_TYPE)
-lex:add_style('deprecated_library', lexer.STYLE_TYPE..',italics')
+lex:add_style('deprecated_library', lexer.STYLE_TYPE .. ',italics')
-- Identifiers.
lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
local longstring = lpeg.Cmt('[' * lpeg.C(P('=')^0) * '[',
- function(input, index, eq)
- local _, e = input:find(']'..eq..']', index, true)
- return (e or #input) + 1
- end)
+ function(input, index, eq)
+ local _, e = input:find(']' .. eq .. ']', index, true)
+ return (e or #input) + 1
+ end)
-- Strings.
-lex:add_rule('string', token(lexer.STRING, lexer.delimited_range("'") +
- lexer.delimited_range('"')) +
- token('longstring', longstring))
+local sq_str = lexer.range("'")
+local dq_str = lexer.range('"')
+lex:add_rule('string', token(lexer.STRING, sq_str + dq_str) +
+ token('longstring', longstring))
lex:add_style('longstring', lexer.STYLE_STRING)
-- Comments.
-lex:add_rule('comment', token(lexer.COMMENT, '--' * (longstring +
- lexer.nonnewline^0)))
+local line_comment = lexer.to_eol('--')
+local block_comment = '--' * longstring
+lex:add_rule('comment', token(lexer.COMMENT, block_comment + line_comment))
-- Numbers.
local lua_integer = P('-')^-1 * (lexer.hex_num + lexer.dec_num)
@@ -133,7 +135,7 @@ lex:add_rule('label', token(lexer.LABEL, '::' * lexer.word * '::'))
-- Operators.
lex:add_rule('operator', token(lexer.OPERATOR, '..' +
- S('+-*/%^#=<>&|~;:,.{}[]()')))
+ S('+-*/%^#=<>&|~;:,.{}[]()')))
-- Fold points.
local function fold_longcomment(text, pos, line, s, symbol)