From ba4fbde33db9b8061effa8f8b2882887ae1800af Mon Sep 17 00:00:00 2001 From: lqdev Date: Tue, 18 May 2021 17:52:18 +0200 Subject: [PATCH] fixed mixed indentation --- data/core/tokenizer.lua | 56 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/data/core/tokenizer.lua b/data/core/tokenizer.lua index f3070995..a4fe2867 100644 --- a/data/core/tokenizer.lua +++ b/data/core/tokenizer.lua @@ -38,23 +38,23 @@ local function find_non_escaped(text, pattern, offset, esc) end end --- 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. --- At most, there are 3 subsyntaxes active at the same time. Beyond that, +-- 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. +-- At most, there are 3 subsyntaxes active at the same time. Beyond that, -- does not support further highlighting. 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 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 - -- syntax we're using. Rather than walking the bytes, and calling into + -- 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` each time, we could probably cache this in a single table. for i=0,2 do local target = bit32.extract(state, i*8, 8) if target ~= 0 then if current_syntax.patterns[target].syntax then 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) current_state = 0 current_level = i+1 @@ -62,7 +62,7 @@ local function retrieve_syntax_state(incoming_syntax, state) current_state = target break end - else + else break end end @@ -77,28 +77,28 @@ function tokenizer.tokenize(incoming_syntax, text, state) if #incoming_syntax.patterns == 0 then return { "normal", text } end - + 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) while i <= #text do -- continue trying to match the end pattern of a pair if we have a state set if current_state > 0 then local p = current_syntax.patterns[current_state] local s, e = find_non_escaped(text, p.pattern[2], i, p.pattern[3]) - + local cont = true -- If we're in subsyntax mode, always check to see if we end our syntax -- first. if subsyntax_info then local ss, se = find_non_escaped( - text, - subsyntax_info.pattern[2], - i, - subsyntax_info.pattern[3] - ) + text, + subsyntax_info.pattern[2], + i, + subsyntax_info.pattern[3] + ) 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 cont = false end @@ -118,17 +118,17 @@ function tokenizer.tokenize(incoming_syntax, text, state) -- Check for end of syntax. if subsyntax_info then local s, e = find_non_escaped( - text, - "^" .. subsyntax_info.pattern[2], - i, - nil + text, + "^" .. subsyntax_info.pattern[2], + i, + nil ) if s then push_token(res, subsyntax_info.type, text:sub(i, e)) current_level = current_level - 1 -- Zero out the state above us, as well as our new current state. 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) i = e + 1 end @@ -143,20 +143,20 @@ function tokenizer.tokenize(incoming_syntax, text, state) if s then -- matched pattern; make and add token local t = text:sub(s, e) - + push_token(res, current_syntax.symbols[t] or p.type, t) -- update state if this was a start|end pattern pair if type(p.pattern) == "table" then state = bit32.replace(state, n, current_level*8, 8) - -- If we've found a new subsyntax, bump our level, and set the - -- appropriate variables. + -- If we've found a new subsyntax, bump our level, and set the + -- appropriate variables. if p.syntax then current_level = current_level + 1 subsyntax_info = p - current_syntax = type(p.syntax) == "table" and - p.syntax or syntax.get(p.syntax) + current_syntax = type(p.syntax) == "table" and + p.syntax or syntax.get(p.syntax) current_state = 0 - else + else current_state = n end end