summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-tex.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-tex.lua')
-rw-r--r--Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-tex.lua85
1 files changed, 58 insertions, 27 deletions
diff --git a/Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-tex.lua b/Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-tex.lua
index 1ff68750fb2..e39ca2baaf2 100644
--- a/Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-tex.lua
+++ b/Master/texmf-dist/context/data/scite/lexers/scite-context-lexer-tex.lua
@@ -59,6 +59,8 @@ local constants = { }
do -- todo: only once, store in global
+ -- commands helpers primitives
+
local definitions = context.loaddefinitions("scite-context-data-interfaces")
if definitions then
@@ -80,10 +82,17 @@ do -- todo: only once, store in global
end
local definitions = context.loaddefinitions("scite-context-data-context")
+ local overloaded = { }
if definitions then
helpers = definitions.helpers or { }
constants = definitions.constants or { }
+ for i=1,#helpers do
+ overloaded[helpers[i]] = true
+ end
+ for i=1,#constants do
+ overloaded[constants[i]] = true
+ end
end
local definitions = context.loaddefinitions("scite-context-data-tex")
@@ -92,20 +101,25 @@ do -- todo: only once, store in global
local function add(data,normal)
for k, v in next, data do
if v ~= "/" and v ~= "-" then
- primitives[#primitives+1] = v
+ if not overloaded[v] then
+ primitives[#primitives+1] = v
+ end
if normal then
- primitives[#primitives+1] = "normal" .. v
+ v = "normal" .. v
+ if not overloaded[v] then
+ primitives[#primitives+1] = v
+ end
end
end
end
end
add(definitions.tex,true)
- add(definitions.etex)
- add(definitions.pdftex)
- add(definitions.aleph)
- add(definitions.omega)
- add(definitions.luatex)
- add(definitions.xetex)
+ add(definitions.etex,true)
+ add(definitions.pdftex,true)
+ add(definitions.aleph,true)
+ add(definitions.omega,true)
+ add(definitions.luatex,true)
+ add(definitions.xetex,true)
end
end
@@ -128,12 +142,13 @@ local checkedword = context.checkedword
local styleofword = context.styleofword
local setwordlist = context.setwordlist
local validwords = false
+local validminimum = 3
-- % language=uk
local knownpreamble = Cmt(#P("% "), function(input,i,_) -- todo : utfbomb
if i < 10 then
- validwords = false
+ validwords, validminimum = false, 3
local s, e, word = find(input,'^(.+)[\n\r]',i) -- combine with match
if word then
local interface = match(word,"interface=([a-z]+)")
@@ -141,7 +156,7 @@ local knownpreamble = Cmt(#P("% "), function(input,i,_) -- todo : utfbomb
currentcommands = commands[interface] or commands.en or { }
end
local language = match(word,"language=([a-z]+)")
- validwords = language and setwordlist(language)
+ validwords, validminimum = setwordlist(language)
end
end
return false
@@ -224,15 +239,17 @@ local p_unit = P("pt") + P("bp") + P("sp") + P("mm") + P("cm") +
--
-- local p_word = Cmt(iwordpattern, function(_,i,s)
-- if validwords then
--- return checkedword(validwords,s,i)
+-- return checkedword(validwords,validminimum,s,i)
-- else
--- return true, { "text", i }
+-- -- return true, { "text", i }
+-- return true, "text", i
-- end
-- end)
--
-- So we use this one instead:
-local p_word = Ct( iwordpattern / function(s) return styleofword(validwords,s) end * Cp() ) -- the function can be inlined
+----- p_word = Ct( iwordpattern / function(s) return styleofword(validwords,validminimum,s) end * Cp() ) -- the function can be inlined
+local p_word = iwordpattern / function(s) return styleofword(validwords,validminimum,s) end * Cp() -- the function can be inlined
----- p_text = (1 - p_grouping - p_special - p_extra - backslash - space + hspace)^1
@@ -343,7 +360,7 @@ local function stopinlinelua_b(_,i,s) -- {
if luastatus == "display" then
return false
elseif luastatus == "inline" then
- lualevel = lualevel + 1
+ lualevel = lualevel + 1 -- ?
return false
else
return true
@@ -372,15 +389,17 @@ contextlexer._reset_parser = function()
lualevel = 0
end
-local luaenvironment = P("luacode")
+local luaenvironment = P("lua") * (P("setups") + P("code") + P(true))
local inlinelua = P("\\") * (
P("ctx") * ( P("lua") + P("command") + P("late") * (P("lua") + P("command")) )
+ P("cld") * ( P("command") + P("context") )
+ + P("luaexpr")
+ + (P("direct") + P("late")) * P("lua")
)
local startlua = P("\\start") * Cmt(luaenvironment,startdisplaylua)
- + inlinelua * space^0 * Cmt(P("{"),startinlinelua)
+ + inlinelua * space^0 * ( Cmt(P("{"),startinlinelua) )
local stoplua = P("\\stop") * Cmt(luaenvironment,stopdisplaylua)
+ Cmt(P("{"),stopinlinelua_b)
@@ -389,7 +408,8 @@ local stoplua = P("\\stop") * Cmt(luaenvironment,stopdisplaylua)
local startluacode = token("embedded", startlua)
local stopluacode = #stoplua * token("embedded", stoplua)
-local metafuncall = ( P("reusable") + P("usable") + P("unique") + P("use") ) * ("MPgraphic")
+local metafuncall = ( P("reusable") + P("usable") + P("unique") + P("use") + P("reuse") ) * ("MPgraphic")
+ + P("uniqueMPpagegraphic")
local metafunenvironment = metafuncall -- ( P("use") + P("reusable") + P("unique") ) * ("MPgraphic")
+ P("MP") * ( P("code")+ P("page") + P("inclusions") + P("initializations") + P("definitions") + P("extensions") + P("graphic") )
@@ -443,22 +463,33 @@ contextlexer._tokenstyles = context.styleset
-- contextlexer._tokenstyles[#contextlexer._tokenstyles + 1] = { cldlexer._NAME..'_whitespace', lexer.style_whitespace }
-- contextlexer._tokenstyles[#contextlexer._tokenstyles + 1] = { mpslexer._NAME..'_whitespace', lexer.style_whitespace }
+local environment = {
+ ["\\start"] = 1, ["\\stop"] = -1,
+ -- ["\\begin"] = 1, ["\\end" ] = -1,
+}
+
+-- local block = {
+-- ["\\begin"] = 1, ["\\end" ] = -1,
+-- }
-local folds = {
- ["\\start"] = 1, ["\\stop" ] = -1,
- ["\\begin"] = 1, ["\\end" ] = -1,
+local group = {
+ ["{"] = 1, ["}"] = -1,
}
-contextlexer._foldsymbols = {
+contextlexer._foldpattern = P("\\" ) * (P("start") + P("stop")) + S("{}") -- separate entry else interference
+
+contextlexer._foldsymbols = { -- these need to be style references
_patterns = {
"\\start", "\\stop", -- regular environments
- "\\begin", "\\end", -- (moveable) blocks
+ -- "\\begin", "\\end", -- (moveable) blocks
+ "[{}]",
},
- ["helper"] = folds,
- ["data"] = folds,
- ["command"] = folds,
- ["user"] = folds, -- csname
- ["grouping"] = folds,
+ ["command"] = environment,
+ ["constant"] = environment,
+ ["data"] = environment,
+ ["user"] = environment,
+ ["embedded"] = environment,
+ ["grouping"] = group,
}
return contextlexer