summaryrefslogtreecommitdiff
path: root/context/data/scite/context/lexers/scite-context-lexer-web.lua
diff options
context:
space:
mode:
Diffstat (limited to 'context/data/scite/context/lexers/scite-context-lexer-web.lua')
-rw-r--r--context/data/scite/context/lexers/scite-context-lexer-web.lua65
1 files changed, 42 insertions, 23 deletions
diff --git a/context/data/scite/context/lexers/scite-context-lexer-web.lua b/context/data/scite/context/lexers/scite-context-lexer-web.lua
index 81a6f90df..6325e3693 100644
--- a/context/data/scite/context/lexers/scite-context-lexer-web.lua
+++ b/context/data/scite/context/lexers/scite-context-lexer-web.lua
@@ -8,25 +8,23 @@ local info = {
local P, R, S = lpeg.P, lpeg.R, lpeg.S
-local lexer = require("scite-context-lexer")
-local context = lexer.context
-local patterns = context.patterns
+local lexers = require("scite-context-lexer")
-local token = lexer.token
-local exact_match = lexer.exact_match
+local patterns = lexers.patterns
+local token = lexers.token
-local weblexer = lexer.new("web","scite-context-lexer-web")
-local whitespace = weblexer.whitespace
+local weblexer = lexers.new("web","scite-context-lexer-web")
+local webwhitespace = weblexer.whitespace
local space = patterns.space -- S(" \n\r\t\f\v")
local any = patterns.any
local restofline = patterns.restofline
-local startofline = patterns.startofline
+local eol = patterns.eol
local period = P(".")
local percent = P("%")
-local spacing = token(whitespace, space^1)
+local spacing = token(webwhitespace, space^1)
local rest = token("default", any)
local eop = P("@>")
@@ -35,33 +33,54 @@ local eos = eop * P("+")^-1 * P("=")
-- we can put some of the next in the web-snippets file
-- is f okay here?
-local texcomment = token("comment", percent * restofline^0)
+-- This one is hard to handle partial because trailing spaces are part of the tex part as well
+-- as the c part so they are bound to that. We could have some special sync signal like a label
+-- with space-like properties (more checking then) or styles that act as boundary (basically any
+-- style + 128 or so). A sunday afternoon challenge. Maybe some newline trickery? Or tag lines
+-- which is possible in scite. Or how about a function hook: foolexer.backtracker(str) where str
+-- matches at the beginning of a line: foolexer.backtracker("@ @c") or a pattern, maybe even a
+-- match from start.
-local texpart = token("label",P("@")) * #spacing
+-- local backtracker = ((lpeg.Cp() * lpeg.P("@ @c")) / function(p) n = p end + lpeg.P(1))^1
+-- local c = os.clock() print(#s) print(lpeg.match(backtracker,s)) print(n) print(c)
+
+-- local backtracker = (lpeg.Cmt(lpeg.P("@ @c"),function(_,p) n = p end) + lpeg.P(1))^1
+-- local c = os.clock() print(#s) print(lpeg.match(backtracker,s)) print(n) print(c)
+
+----- somespace = spacing
+----- somespace = token("whitespace",space^1)
+local somespace = space^1
+
+local texpart = token("label",P("@")) * #somespace
+ token("label",P("@") * P("*")^1) * token("function",(1-period)^1) * token("label",period)
-local midpart = token("label",P("@d")) * #spacing
- + token("label",P("@f")) * #spacing
-local cpppart = token("label",P("@c")) * #spacing
- + token("label",P("@p")) * #spacing
+local midpart = token("label",P("@d")) * #somespace
+ + token("label",P("@f")) * #somespace
+local cpppart = token("label",P("@c")) * #somespace
+ + token("label",P("@p")) * #somespace
+ token("label",P("@") * S("<(")) * token("function",(1-eop)^1) * token("label",eos)
local anypart = P("@") * ( P("*")^1 + S("dfcp") + space^1 + S("<(") * (1-eop)^1 * eos )
local limbo = 1 - anypart - percent
-local texlexer = lexer.load("scite-context-lexer-tex-web")
-local cpplexer = lexer.load("scite-context-lexer-cpp-web")
+weblexer.backtracker = eol^1 * P("@ @c")
+-- weblexer.foretracker = (space-eol)^0 * eol^1 * P("@") * space + anypart
+weblexer.foretracker = anypart
-lexer.embed_lexer(weblexer, texlexer, texpart + limbo, #anypart)
-lexer.embed_lexer(weblexer, cpplexer, cpppart + midpart, #anypart)
+local texlexer = lexers.load("scite-context-lexer-tex-web")
+local cpplexer = lexers.load("scite-context-lexer-cpp-web")
-local texcomment = token("comment", percent * restofline^0)
+-- local texlexer = lexers.load("scite-context-lexer-tex")
+-- local cpplexer = lexers.load("scite-context-lexer-cpp")
-weblexer._rules = {
+lexers.embed(weblexer, texlexer, texpart + limbo, #anypart)
+lexers.embed(weblexer, cpplexer, cpppart + midpart, #anypart)
+
+local texcomment = token("comment", percent * restofline^0)
+
+weblexer.rules = {
{ "whitespace", spacing },
{ "texcomment", texcomment }, -- else issues with first tex section
{ "rest", rest },
}
-weblexer._tokenstyles = context.styleset
-
return weblexer