Merge pull request #1034 from Guldoman/PR_escape_start_patterns

Check if "open" pattern is escaped
This commit is contained in:
Jefferson González 2022-06-15 16:51:34 -04:00 committed by GitHub
commit d2fd5c9df7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -194,15 +194,21 @@ function tokenizer.tokenize(incoming_syntax, text, state)
res[1] = char_pos_1
res[2] = char_pos_2
end
if res[1] and close and target[3] then
if res[1] and target[3] then
-- Check to see if the escaped character is there,
-- and if it is not itself escaped.
local count = 0
for i = res[1] - 1, 1, -1 do
if text:ubyte(i) ~= target[3]:ubyte() then break end
count = count + 1
end
-- Check to see if the escaped character is there,
-- and if it is not itself escaped.
if count % 2 == 0 then break end
if count % 2 == 0 then
-- The match is not escaped, so confirm it
break
elseif not close then
-- The *open* match is escaped, so avoid it
return
end
end
until not res[1] or not close or not target[3]
return table.unpack(res)