Fix malformed pattern check for group patterns in tokenizer

If the token type was a simple string (and not a table), the size of the 
string was used instead of `1`.
This commit is contained in:
Guldoman 2022-06-15 19:33:58 +02:00
parent d8a3987aa4
commit 5027a0f12b
No known key found for this signature in database
GPG Key ID: EA928C8BDA1A8825
1 changed files with 9 additions and 9 deletions

View File

@ -259,16 +259,16 @@ function tokenizer.tokenize(incoming_syntax, text, state)
local matched = false
for n, p in ipairs(current_syntax.patterns) do
local find_results = { find_text(text, p, i, true, false) }
if #find_results - 1 > #p.type then
if not bad_patterns[current_syntax] then
bad_patterns[current_syntax] = { }
end
if not bad_patterns[current_syntax][n] then
bad_patterns[current_syntax][n] = true
core.error("Malformed pattern #%d in %s language plugin", n, current_syntax.name or "unnamed")
end
end
if find_results[1] then
if #find_results - 1 > (type(p.type) == "table" and #p.type or 1) then
if not bad_patterns[current_syntax] then
bad_patterns[current_syntax] = { }
end
if not bad_patterns[current_syntax][n] then
bad_patterns[current_syntax][n] = true
core.error("Malformed pattern #%d in %s language plugin", n, current_syntax.name or "unnamed")
end
end
-- matched pattern; make and add tokens
push_tokens(res, current_syntax, p, text, find_results)
-- update state if this was a start|end pattern pair