fixed mixed indentation
This commit is contained in:
parent
92322986b8
commit
ba4fbde33d
@ -38,23 +38,23 @@ local function find_non_escaped(text, pattern, offset, esc)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- State is a 32-bit number that is four separate bytes, illustrating how many
|
-- State is a 32-bit number that is four separate bytes, illustrating how many
|
||||||
-- differnet delimiters we have open, and which subsyntaxes we have active.
|
-- differnet delimiters we have open, and which subsyntaxes we have active.
|
||||||
-- At most, there are 3 subsyntaxes active at the same time. Beyond that,
|
-- At most, there are 3 subsyntaxes active at the same time. Beyond that,
|
||||||
-- does not support further highlighting.
|
-- does not support further highlighting.
|
||||||
local function retrieve_syntax_state(incoming_syntax, state)
|
local function retrieve_syntax_state(incoming_syntax, state)
|
||||||
local current_syntax, subsyntax_info, current_state, current_level =
|
local current_syntax, subsyntax_info, current_state, current_level =
|
||||||
incoming_syntax, nil, state, 0
|
incoming_syntax, nil, state, 0
|
||||||
if state > 0 and (state > 255 or current_syntax.patterns[state].syntax) then
|
if state > 0 and (state > 255 or current_syntax.patterns[state].syntax) then
|
||||||
-- If we have higher bits, then decode them one at a time, and find which
|
-- If we have higher bits, then decode them one at a time, and find which
|
||||||
-- syntax we're using. Rather than walking the bytes, and calling into
|
-- syntax we're using. Rather than walking the bytes, and calling into
|
||||||
-- `syntax` each time, we could probably cache this in a single table.
|
-- `syntax` each time, we could probably cache this in a single table.
|
||||||
for i=0,2 do
|
for i=0,2 do
|
||||||
local target = bit32.extract(state, i*8, 8)
|
local target = bit32.extract(state, i*8, 8)
|
||||||
if target ~= 0 then
|
if target ~= 0 then
|
||||||
if current_syntax.patterns[target].syntax then
|
if current_syntax.patterns[target].syntax then
|
||||||
subsyntax_info = current_syntax.patterns[target]
|
subsyntax_info = current_syntax.patterns[target]
|
||||||
current_syntax = type(subsyntax_info.syntax) == "table" and
|
current_syntax = type(subsyntax_info.syntax) == "table" and
|
||||||
subsyntax_info.syntax or syntax.get(subsyntax_info.syntax)
|
subsyntax_info.syntax or syntax.get(subsyntax_info.syntax)
|
||||||
current_state = 0
|
current_state = 0
|
||||||
current_level = i+1
|
current_level = i+1
|
||||||
@ -62,7 +62,7 @@ local function retrieve_syntax_state(incoming_syntax, state)
|
|||||||
current_state = target
|
current_state = target
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -77,28 +77,28 @@ function tokenizer.tokenize(incoming_syntax, text, state)
|
|||||||
if #incoming_syntax.patterns == 0 then
|
if #incoming_syntax.patterns == 0 then
|
||||||
return { "normal", text }
|
return { "normal", text }
|
||||||
end
|
end
|
||||||
|
|
||||||
state = state or 0
|
state = state or 0
|
||||||
local current_syntax, subsyntax_info, current_state, current_level =
|
local current_syntax, subsyntax_info, current_state, current_level =
|
||||||
retrieve_syntax_state(incoming_syntax, state)
|
retrieve_syntax_state(incoming_syntax, state)
|
||||||
while i <= #text do
|
while i <= #text do
|
||||||
-- continue trying to match the end pattern of a pair if we have a state set
|
-- continue trying to match the end pattern of a pair if we have a state set
|
||||||
if current_state > 0 then
|
if current_state > 0 then
|
||||||
local p = current_syntax.patterns[current_state]
|
local p = current_syntax.patterns[current_state]
|
||||||
local s, e = find_non_escaped(text, p.pattern[2], i, p.pattern[3])
|
local s, e = find_non_escaped(text, p.pattern[2], i, p.pattern[3])
|
||||||
|
|
||||||
local cont = true
|
local cont = true
|
||||||
-- If we're in subsyntax mode, always check to see if we end our syntax
|
-- If we're in subsyntax mode, always check to see if we end our syntax
|
||||||
-- first.
|
-- first.
|
||||||
if subsyntax_info then
|
if subsyntax_info then
|
||||||
local ss, se = find_non_escaped(
|
local ss, se = find_non_escaped(
|
||||||
text,
|
text,
|
||||||
subsyntax_info.pattern[2],
|
subsyntax_info.pattern[2],
|
||||||
i,
|
i,
|
||||||
subsyntax_info.pattern[3]
|
subsyntax_info.pattern[3]
|
||||||
)
|
)
|
||||||
if ss and (s == nil or ss < s) then
|
if ss and (s == nil or ss < s) then
|
||||||
push_token(res, p.type, text:sub(i, ss - 1))
|
push_token(res, p.type, text:sub(i, ss - 1))
|
||||||
i = ss
|
i = ss
|
||||||
cont = false
|
cont = false
|
||||||
end
|
end
|
||||||
@ -118,17 +118,17 @@ function tokenizer.tokenize(incoming_syntax, text, state)
|
|||||||
-- Check for end of syntax.
|
-- Check for end of syntax.
|
||||||
if subsyntax_info then
|
if subsyntax_info then
|
||||||
local s, e = find_non_escaped(
|
local s, e = find_non_escaped(
|
||||||
text,
|
text,
|
||||||
"^" .. subsyntax_info.pattern[2],
|
"^" .. subsyntax_info.pattern[2],
|
||||||
i,
|
i,
|
||||||
nil
|
nil
|
||||||
)
|
)
|
||||||
if s then
|
if s then
|
||||||
push_token(res, subsyntax_info.type, text:sub(i, e))
|
push_token(res, subsyntax_info.type, text:sub(i, e))
|
||||||
current_level = current_level - 1
|
current_level = current_level - 1
|
||||||
-- Zero out the state above us, as well as our new current state.
|
-- Zero out the state above us, as well as our new current state.
|
||||||
state = bit32.replace(state, 0, current_level*8, 16)
|
state = bit32.replace(state, 0, current_level*8, 16)
|
||||||
current_syntax, subsyntax_info, current_state, current_level =
|
current_syntax, subsyntax_info, current_state, current_level =
|
||||||
retrieve_syntax_state(incoming_syntax, state)
|
retrieve_syntax_state(incoming_syntax, state)
|
||||||
i = e + 1
|
i = e + 1
|
||||||
end
|
end
|
||||||
@ -143,20 +143,20 @@ function tokenizer.tokenize(incoming_syntax, text, state)
|
|||||||
if s then
|
if s then
|
||||||
-- matched pattern; make and add token
|
-- matched pattern; make and add token
|
||||||
local t = text:sub(s, e)
|
local t = text:sub(s, e)
|
||||||
|
|
||||||
push_token(res, current_syntax.symbols[t] or p.type, t)
|
push_token(res, current_syntax.symbols[t] or p.type, t)
|
||||||
-- update state if this was a start|end pattern pair
|
-- update state if this was a start|end pattern pair
|
||||||
if type(p.pattern) == "table" then
|
if type(p.pattern) == "table" then
|
||||||
state = bit32.replace(state, n, current_level*8, 8)
|
state = bit32.replace(state, n, current_level*8, 8)
|
||||||
-- If we've found a new subsyntax, bump our level, and set the
|
-- If we've found a new subsyntax, bump our level, and set the
|
||||||
-- appropriate variables.
|
-- appropriate variables.
|
||||||
if p.syntax then
|
if p.syntax then
|
||||||
current_level = current_level + 1
|
current_level = current_level + 1
|
||||||
subsyntax_info = p
|
subsyntax_info = p
|
||||||
current_syntax = type(p.syntax) == "table" and
|
current_syntax = type(p.syntax) == "table" and
|
||||||
p.syntax or syntax.get(p.syntax)
|
p.syntax or syntax.get(p.syntax)
|
||||||
current_state = 0
|
current_state = 0
|
||||||
else
|
else
|
||||||
current_state = n
|
current_state = n
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user