diff options
Diffstat (limited to 'Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-lua.lua')
-rw-r--r-- | Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-lua.lua | 123 |
1 files changed, 100 insertions, 23 deletions
diff --git a/Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-lua.lua b/Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-lua.lua index 0ace7afc6ff..9672e110e4f 100644 --- a/Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-lua.lua +++ b/Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-lua.lua @@ -6,6 +6,8 @@ local info = { license = "see context related readme files", } +-- todo: _G.print (keep _G colored) + if not lexer._CONTEXTEXTENSIONS then require("scite-context-lexer") end local lexer = lexer @@ -34,18 +36,32 @@ local keywords = { } local functions = { - 'assert', 'collectgarbage', 'dofile', 'error', 'getfenv', 'getmetatable', - 'ipairs', 'load', 'loadfile', 'loadstring', 'module', 'next', 'pairs', - 'pcall', 'print', 'rawequal', 'rawget', 'rawset', 'require', 'setfenv', - 'setmetatable', 'tonumber', 'tostring', 'type', 'unpack', 'xpcall', "select", + 'assert', 'collectgarbage', 'dofile', 'error', 'getmetatable', + 'ipairs', 'load', 'loadfile', 'module', 'next', 'pairs', + 'pcall', 'print', 'rawequal', 'rawget', 'rawset', 'require', + 'setmetatable', 'tonumber', 'tostring', 'type', 'unpack', 'xpcall', 'select', + + "string", "table", "coroutine", "debug", "file", "io", "lpeg", "math", "os", "package", "bit32", } local constants = { - '_G', '_VERSION', '_M', "...", + '_G', '_VERSION', '_M', '...', '_ENV', + -- here too + '__add', '__call', '__concat', '__div', '__eq', '__gc', '__index', + '__le', '__lt', '__metatable', '__mode', '__mul', '__newindex', + '__pow', '__sub', '__tostring', '__unm', +} + +local internals = { -- __ + 'add', 'call', 'concat', 'div', 'eq', 'gc', 'index', + 'le', 'lt', 'metatable', 'mode', 'mul', 'newindex', + 'pow', 'sub', 'tostring', 'unm', } local depricated = { "arg", "arg.n", + "loadstring", "setfenv", "getfenv", + "pack", } local csnames = { -- todo: option @@ -147,7 +163,7 @@ local operator = token("special", S('+-*/%^#=<>;:,{}[]().') + P('~=') ) -- local structure = token("special", S('{}[]()')) local optionalspace = spacing^0 -local hasargument = #S("{(") +local hasargument = #S("{([") local gotokeyword = token("keyword", P("goto")) * spacing @@ -156,14 +172,28 @@ local gotolabel = token("keyword", P("::")) * token("grouping",validword) * token("keyword", P("::")) -local keyword = token("keyword", exact_match(keywords )) -local builtin = token("plain", exact_match(functions)) -local constant = token("data", exact_match(constants)) -local csname = token("user", exact_match(csnames )) +local p_keywords = exact_match(keywords) +local p_functions = exact_match(functions) +local p_constants = exact_match(constants) +local p_internals = P("__") + * exact_match(internals) +local p_csnames = exact_match(csnames) + +local keyword = token("keyword", p_keywords) +local builtin = token("plain", p_functions) +local constant = token("data", p_constants) +local internal = token("data", p_internals) +local csname = token("user", p_csnames) * ( optionalspace * hasargument - + ( optionalspace * token("special", P(".")) * optionalspace * token("user", validword) )^1 + + ( optionalspace * token("special", S(".:")) * optionalspace * token("user", validword) )^1 ) +local identifier = token("default", validword) + * ( optionalspace * token("special", S(".:")) * optionalspace * ( + token("warning", p_keywords) + + token("data", p_internals) + + token("default", validword ) + ) )^0 lualexer._rules = { { 'whitespace', spacing }, @@ -178,36 +208,83 @@ lualexer._rules = { { 'number', number }, { 'longcomment', longcomment }, { 'shortcomment', shortcomment }, --- { 'number', number }, { 'label', gotolabel }, { 'operator', operator }, { 'rest', rest }, } +-- -- experiment +-- +-- local idtoken = R("az","AZ","__") +-- +-- function context.one_of_match(specification) +-- local pattern = idtoken -- the concat catches _ etc +-- local list = { } +-- for i=1,#specification do +-- local style = specification[i][1] +-- local words = specification[i][2] +-- pattern = pattern + S(table.concat(words)) +-- for i=1,#words do +-- list[words[i]] = style +-- end +-- end +-- return Cmt(pattern^1, function(_,i,s) +-- local style = list[s] +-- if style then +-- return true, { style, i } -- and i or nil +-- else +-- -- fail +-- end +-- end) +-- end +-- +-- local whatever = context.one_of_match { +-- { "keyword", keywords }, -- keyword +-- { "plain", functions }, -- builtin +-- { "data", constants }, -- constant +-- } +-- +-- lualexer._rules = { +-- { 'whitespace', spacing }, +-- { 'whatever', whatever }, +-- { 'csname', csname }, +-- { 'goto', gotokeyword }, +-- { 'identifier', identifier }, +-- { 'string', string }, +-- { 'number', number }, +-- { 'longcomment', longcomment }, +-- { 'shortcomment', shortcomment }, +-- { 'label', gotolabel }, +-- { 'operator', operator }, +-- { 'rest', rest }, +-- } + lualexer._tokenstyles = context.styleset +-- lualexer._foldpattern = R("az")^2 + S("{}[]") -- separate entry else interference + +lualexer._foldpattern = (P("end") + P("if") + P("do") + P("function") + P("repeat") + P("until")) * P(#(1 - R("az"))) + + S("{}[]") + lualexer._foldsymbols = { _patterns = { - -- '%l+', -- costly - -- '%l%l+', '[a-z][a-z]+', - -- '[%({%)}%[%]]', '[{}%[%]]', }, ['keyword'] = { -- challenge: if=0 then=1 else=-1 elseif=-1 - ['if'] = 1, - ['end'] = -1, - ['do'] = 1, - ['function'] = 1, - ['repeat'] = 1, + ['if'] = 1, -- if .. [then|else] .. end + ['do'] = 1, -- [while] do .. end + ['function'] = 1, -- function .. end + ['repeat'] = 1, -- repeat .. until ['until'] = -1, + ['end'] = -1, }, ['comment'] = { ['['] = 1, [']'] = -1, }, - ['quote'] = { -- to be tested - ['['] = 1, [']'] = -1, - }, + -- ['quote'] = { -- confusing + -- ['['] = 1, [']'] = -1, + -- }, ['special'] = { -- ['('] = 1, [')'] = -1, ['{'] = 1, ['}'] = -1, |