summaryrefslogtreecommitdiff
path: root/context/data/scite/context/lexers/scite-context-lexer-txt.lua
diff options
context:
space:
mode:
Diffstat (limited to 'context/data/scite/context/lexers/scite-context-lexer-txt.lua')
-rw-r--r--context/data/scite/context/lexers/scite-context-lexer-txt.lua63
1 files changed, 26 insertions, 37 deletions
diff --git a/context/data/scite/context/lexers/scite-context-lexer-txt.lua b/context/data/scite/context/lexers/scite-context-lexer-txt.lua
index 8ecfff7cb..5b48657a9 100644
--- a/context/data/scite/context/lexers/scite-context-lexer-txt.lua
+++ b/context/data/scite/context/lexers/scite-context-lexer-txt.lua
@@ -9,53 +9,45 @@ local info = {
local P, S, Cmt, Cp = lpeg.P, lpeg.S, lpeg.Cmt, lpeg.Cp
local find, match = string.find, string.match
-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 patterns = lexers.patterns
+local token = lexers.token
+local styleofword = lexers.styleofword
+local setwordlist = lexers.setwordlist
-local textlexer = lexer.new("txt","scite-context-lexer-txt")
-local whitespace = textlexer.whitespace
+local textlexer = lexers.new("txt","scite-context-lexer-txt")
+local textwhitespace = textlexer.whitespace
+
+local space = patterns.space
+local any = patterns.any
+local wordtoken = patterns.wordtoken
+local wordpattern = patterns.wordpattern
-local space = patterns.space
-local any = patterns.any
-local wordtoken = patterns.wordtoken
-local wordpattern = patterns.wordpattern
-local checkedword = context.checkedword
-local styleofword = context.styleofword
-local setwordlist = context.setwordlist
local validwords = false
local validminimum = 3
--- local styleset = context.newstyleset {
--- "default",
--- "text", "okay", "error", "warning",
--- "preamble",
--- }
-
--- [#!-%] language=uk
-
-local p_preamble = Cmt((S("#!-%") * P(" ")), function(input,i,_) -- todo: utf bomb no longer #
- if i == 1 then -- < 10 then
- validwords, validminimum = false, 3
- local s, e, line = find(input,"^[#!%-%%](.+)[\n\r]",i)
- if line then
- local language = match(line,"language=([a-z]+)")
- if language then
- validwords, validminimum = setwordlist(language)
- end
+-- [#!-%] language=uk (space before key is mandate)
+
+local p_preamble = Cmt((S("#!-%") * P(" ") + P(true)), function(input,i)
+ validwords = false
+ validminimum = 3
+ local s, e, line = find(input,"^[#!%-%%](.+)[\n\r]",1)
+ if line then
+ local language = match(line," language=([a-z]+)")
+ if language then
+ validwords, validminimum = setwordlist(language)
end
end
- return false
+ return false -- so we go back and now handle the line as text
end)
local t_preamble =
token("preamble", p_preamble)
local t_word =
- wordpattern / function(s) return styleofword(validwords,validminimum,s) end * Cp() -- the function can be inlined
+ C(wordpattern) * Cp() / function(s,p) return styleofword(validwords,validminimum,s,p) end -- a bit of a hack
local t_text =
token("default", wordtoken^1)
@@ -64,9 +56,9 @@ local t_rest =
token("default", (1-wordtoken-space)^1)
local t_spacing =
- token(whitespace, space^1)
+ token(textwhitespace, space^1)
-textlexer._rules = {
+textlexer.rules = {
{ "whitespace", t_spacing },
{ "preamble", t_preamble },
{ "word", t_word }, -- words >= 3
@@ -74,7 +66,4 @@ textlexer._rules = {
{ "rest", t_rest },
}
-textlexer._LEXBYLINE = true -- new (needs testing, not yet as the system changed in 3.24)
-textlexer._tokenstyles = context.styleset
-
return textlexer