summaryrefslogtreecommitdiff
path: root/context/data/scite/lexers
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2011-09-17 17:20:13 +0300
committerMarius <mariausol@gmail.com>2011-09-17 17:20:13 +0300
commit6a1645d499e26ab02b365dd4b93da771815d8c0d (patch)
tree35f096770997609a39a2d777421b85c1e45504e8 /context/data/scite/lexers
parent32956188684f3f0bd1cc077a6870fdd57fea0cfc (diff)
downloadcontext-6a1645d499e26ab02b365dd4b93da771815d8c0d.tar.gz
beta 2011.09.17 15:56
Diffstat (limited to 'context/data/scite/lexers')
-rw-r--r--context/data/scite/lexers/scite-context-lexer-cld.lua2
-rw-r--r--context/data/scite/lexers/scite-context-lexer-lua.lua6
-rw-r--r--context/data/scite/lexers/scite-context-lexer-mps.lua11
-rw-r--r--context/data/scite/lexers/scite-context-lexer-tex.lua57
-rw-r--r--context/data/scite/lexers/scite-context-lexer.lua48
-rw-r--r--context/data/scite/lexers/themes/scite-context-theme.lua8
6 files changed, 108 insertions, 24 deletions
diff --git a/context/data/scite/lexers/scite-context-lexer-cld.lua b/context/data/scite/lexers/scite-context-lexer-cld.lua
index 632a7672c..f81119adf 100644
--- a/context/data/scite/lexers/scite-context-lexer-cld.lua
+++ b/context/data/scite/lexers/scite-context-lexer-cld.lua
@@ -1,6 +1,6 @@
local info = {
version = 1.002,
- comment = "scintilla lpeg lexer for cld/lua",
+ comment = "scintilla lpeg lexer for cld",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files",
diff --git a/context/data/scite/lexers/scite-context-lexer-lua.lua b/context/data/scite/lexers/scite-context-lexer-lua.lua
index 2a0f48026..49799a978 100644
--- a/context/data/scite/lexers/scite-context-lexer-lua.lua
+++ b/context/data/scite/lexers/scite-context-lexer-lua.lua
@@ -1,13 +1,11 @@
local info = {
version = 1.002,
- comment = "scintilla lpeg lexer for cld/lua",
+ comment = "scintilla lpeg lexer for lua",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files",
}
--- Adapted from lua.lua by Mitchell who based it on a lexer by Peter Odding.
-
local lexer = lexer
local token, style, colors, exact_match, no_style = lexer.token, lexer.style, lexer.colors, lexer.exact_match, lexer.style_nothing
local P, R, S, C, Cg, Cb, Cs, Cmt = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cg, lpeg.Cb, lpeg.Cs, lpeg.Cmt
@@ -20,6 +18,8 @@ local cldlexer = _M
_directives = { } -- communication channel
+-- this will be eextended
+
local keywords = {
'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function',
'if', 'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true',
diff --git a/context/data/scite/lexers/scite-context-lexer-mps.lua b/context/data/scite/lexers/scite-context-lexer-mps.lua
index 188c98c73..2d8cc3a70 100644
--- a/context/data/scite/lexers/scite-context-lexer-mps.lua
+++ b/context/data/scite/lexers/scite-context-lexer-mps.lua
@@ -56,6 +56,10 @@ local number = sign^-1 * ( -- at most one
+ digit^1 -- 10
)
+local cstokentex = R("az","AZ","\127\255") + S("@!?_")
+
+-- we could collapse as in tex
+
local spacing = token(whitespace, space^1)
local rest = token('default', any)
local comment = token('comment', P('%') * (1-S("\n\r"))^0)
@@ -66,10 +70,10 @@ local quoted = token('quote', dquote)
* token('string', P(1-dquote)^1)
* token('quote', dquote)
local primitive = token('primitive', exact_match(primitivecommands))
------ csname = token('user', cstoken^1)
-local identifier = token('default', cstoken^1)
+local identifier = token('default', cstoken)
local number = token('number', number)
-local special = token('special', S("#()[]<>=:\""))
+local special = token('special', S("#()[]<>=:\"")) -- or else := <> etc split
+local texlike = token('string', P("\\") * cstokentex^1)
local extra = token('extra', S("`~%^&_-+/\'|\\"))
_rules = {
@@ -83,6 +87,7 @@ _rules = {
{ 'number', number },
{ 'quoted', quoted },
{ 'special', special },
+-- { 'texlike', texlike },
{ 'extra', extra },
{ 'rest', rest },
}
diff --git a/context/data/scite/lexers/scite-context-lexer-tex.lua b/context/data/scite/lexers/scite-context-lexer-tex.lua
index dac3ada63..340c3f75e 100644
--- a/context/data/scite/lexers/scite-context-lexer-tex.lua
+++ b/context/data/scite/lexers/scite-context-lexer-tex.lua
@@ -37,7 +37,7 @@ local global, string, table, lpeg = _G, string, table, lpeg
local token, style, colors, exact_match, no_style = lexer.token, lexer.style, lexer.colors, lexer.exact_match, lexer.style_nothing
local P, R, S, V, C, Cmt, Cp, Cc, Ct = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.C, lpeg.Cmt, lpeg.Cp, lpeg.Cc, lpeg.Ct
local type, next, pcall, loadfile, setmetatable = type, next, pcall, loadfile, setmetatable
-local find, match = string.find, string.match
+local find, match, lower = string.find, string.match, string.lower
module(...)
@@ -111,14 +111,19 @@ local knowncommand = Cmt(cstoken^1, function(_,i,s)
return currentcommands[s] and i
end)
+local validwords = false
+
local knownpreamble = Cmt(P("% "), function(input,i,_)
if i < 10 then
+ validwords = false
local s, e, word = find(input,'^(.+)[\n\r]',i) -- combine with match
if word then
local interface = match(word,"interface=(..)")
if interface then
currentcommands = commands[interface] or commands.en or { }
end
+ local language = match(word,"language=(..)")
+ validwords = language and lexer.context.setwordlist(language)
end
end
return false
@@ -169,22 +174,51 @@ local whitespace = contextlexer.WHITESPACE -- triggers states
local space = lexer.space -- S(" \n\r\t\f\v")
local any = lexer.any
+local backslash = P("\\")
+local hspace = S(" \t")
local p_spacing = space^1
local p_rest = any
local p_preamble = knownpreamble
local p_comment = commentline
-local p_command = P('\\') * knowncommand
-local p_constant = P('\\') * exact_match(constants)
-local p_helper = P('\\') * exact_match(helpers)
-local p_primitive = P('\\') * exact_match(primitives)
+local p_command = backslash * knowncommand
+local p_constant = backslash * exact_match(constants)
+local p_helper = backslash * exact_match(helpers)
+local p_primitive = backslash * exact_match(primitives)
local p_ifprimitive = P('\\if') * cstoken^1
-local p_csname = P('\\') * (cstoken^1 + P(1))
+local p_csname = backslash * (cstoken^1 + P(1))
local p_grouping = S("{$}")
local p_special = S("#()[]<>=\"")
local p_extra = S("`~%^&_-+/\'|")
-local p_text = cstoken^1
+local p_text = cstoken^1 --maybe add punctuation and space
+
+-- no looking back = #(1-S("[=")) * cstoken^3 * #(1-S("=]"))
+
+local p_word = Cmt(cstoken^3, function(_,i,s)
+ if not validwords then
+ return true, { "text", i }
+ else
+ -- keys are lower
+ local word = validwords[s]
+ if word == s then
+ return true, { "okay", i } -- exact match
+ elseif word then
+ return true, { "warning", i } -- case issue
+ else
+ local word = validwords[lower(s)]
+ if word == s then
+ return true, { "okay", i } -- exact match
+ elseif word then
+ return true, { "warning", i } -- case issue
+ else
+ return true, { "error", i }
+ end
+ end
+ end
+end)
+
+-- local p_text = (1 - p_grouping - p_special - p_extra - backslash - space + hspace)^1
-- keep key pressed at end-of syst-aux.mkiv:
--
@@ -202,7 +236,6 @@ if option == 1 then
p_grouping = p_grouping^1
p_special = p_special^1
p_extra = p_extra^1
- p_text = p_text^1
p_command = p_command^1
p_constant = p_constant^1
@@ -218,7 +251,6 @@ elseif option == 2 then
p_grouping = (p_grouping * included)^1
p_special = (p_special * included)^1
p_extra = (p_extra * included)^1
- p_text = (p_text * included)^1
p_command = (p_command * included)^1
p_constant = (p_constant * included)^1
@@ -243,6 +275,8 @@ local grouping = token('grouping', p_grouping )
local special = token('special', p_special )
local extra = token('extra', p_extra )
local text = token('default', p_text )
+----- word = token("okay", p_word )
+local word = p_word
----- startluacode = token("grouping", P("\\startluacode"))
----- stopluacode = token("grouping", P("\\stopluacode"))
@@ -261,6 +295,7 @@ end
local function stopdisplaylua(_,i,s)
local ok = luatag == s
if ok then
+cldlexer._directives.cld_inline = false
luastatus = false
end
return ok
@@ -298,6 +333,7 @@ local function stopinlinelua_e(_,i,s) -- }
lualevel = lualevel - 1
local ok = lualevel <= 0
if ok then
+cldlexer._directives.cld_inline = false
luastatus = false
end
return ok
@@ -347,7 +383,8 @@ lexer.embed_lexer(contextlexer, mpslexer, startmetafuncode, stopmetafuncode)
_rules = {
{ "whitespace", spacing },
{ "preamble", preamble },
- { "text", text },
+ { "word", word },
+ -- { "text", text },
{ "comment", comment },
{ "constant", constant },
{ "helper", helper },
diff --git a/context/data/scite/lexers/scite-context-lexer.lua b/context/data/scite/lexers/scite-context-lexer.lua
index 4848dc9d9..20af5d68f 100644
--- a/context/data/scite/lexers/scite-context-lexer.lua
+++ b/context/data/scite/lexers/scite-context-lexer.lua
@@ -24,12 +24,12 @@ local info = {
-- an issue we can rewrite the main lex function (memorize the grammars and speed up the
-- byline variant).
-local R, P, S, Cp, Cs, Ct, Cmt, Cc = lpeg.R, lpeg.P, lpeg.S, lpeg.Cp, lpeg.Cs, lpeg.Ct, lpeg.Cmt, lpeg.Cc
+local R, P, S, C, Cp, Cs, Ct, Cmt, Cc, Cf, Cg = lpeg.R, lpeg.P, lpeg.S, lpeg.C, lpeg.Cp, lpeg.Cs, lpeg.Ct, lpeg.Cmt, lpeg.Cc, lpeg.Cf, lpeg.Cg
local lpegmatch = lpeg.match
local find, gmatch, match, lower, upper, gsub = string.find, string.gmatch, string.match, string.lower, string.upper, string.gsub
local concat = table.concat
local global = _G
-local type, next, setmetatable = type, next, setmetatable
+local type, next, setmetatable, rawset = type, next, setmetatable, rawset
dofile(_LEXERHOME .. '/lexer.lua')
@@ -42,7 +42,7 @@ local locations = {
}
local function collect(name)
- local definitions = loadfile(name .. ".lua")
+ local definitions = loadfile(name .. ".luc") or loadfile(name .. ".lua")
if type(definitions) == "function" then
definitions = definitions()
end
@@ -423,11 +423,45 @@ end
-- todo: keywords: one lookup and multiple matches
--- function lexer.context.token(name, patt)
--- return Ct(patt * Cc(name) * Cp())
--- end
+function lexer.context.token(name, patt)
+ return Ct(patt * Cc(name) * Cp())
+end
lexer.fold = lexer.context.fold
lexer.lex = lexer.context.lex
--- lexer.token = lexer.context.token
+lexer.token = lexer.context.token
lexer.exact_match = lexer.context.exact_match
+
+-- spell checking (we can only load lua files)
+
+local lists = { }
+
+local splitter = (Cf(Ct("") * (Cg(C((1-S(" \t\n\r"))^1 * Cc(true))) + P(1))^1,rawset) )^0
+local splitter = (Cf(Ct("") * (Cg(C(R("az","AZ","\127\255")^1) * Cc(true)) + P(1))^1,rawset) )^0
+
+local function splitwords(words)
+ return lpegmatch(splitter,words)
+end
+
+function lexer.context.setwordlist(tag)
+ if not tag or tag == "" then
+ return false
+ elseif lists[tag] ~= nil then
+ return lists[tag]
+ else
+ local list = collect("spell-" .. tag)
+ if not list or type(list) ~= "table" then
+ lists[tag] = false
+ return nil
+ elseif type(list.words) == "string" then
+ list = splitwords(list.words)
+ lists[tag] = list
+ return list
+ else
+ list = list.words or false
+ lists[tag] = list
+ return list
+ end
+ end
+end
+
diff --git a/context/data/scite/lexers/themes/scite-context-theme.lua b/context/data/scite/lexers/themes/scite-context-theme.lua
index 360a5d435..94f623cd8 100644
--- a/context/data/scite/lexers/themes/scite-context-theme.lua
+++ b/context/data/scite/lexers/themes/scite-context-theme.lua
@@ -70,7 +70,9 @@ style_char = style { fore = colors.magenta }
style_class = style { fore = colors.black, bold = true }
style_constant = style { fore = colors.cyan, bold = true }
style_definition = style { fore = colors.black, bold = true }
+style_okay = style { fore = colors.dark }
style_error = style { fore = colors.red }
+style_warning = style { fore = colors.orange }
style_function = style { fore = colors.black, bold = true }
style_operator = style { fore = colors.blue }
style_preproc = style { fore = colors.yellow, bold = true }
@@ -86,6 +88,8 @@ style_indentguide = style { fore = colors.linepanel, back = colors.white
style_calltip = style { fore = colors.white, back = colors.tippanel }
style_controlchar = style_nothing
+-- only bold seems to work
+
lexer.context.styles = {
-- ["whitespace"] = style_whitespace,
@@ -108,6 +112,10 @@ lexer.context.styles = {
["extra"] = style { fore = colors.yellow },
["quote"] = style { fore = colors.blue, bold = true },
+ ["okay"] = style_okay,
+ ["warning"] = style_warning,
+ ["error"] = style_error,
+
}
local styleset = { }