diff options
author | Georgi Kirilov <> | 2023-10-10 05:30:08 +0800 |
---|---|---|
committer | Georgi Kirilov <> | 2023-10-15 17:07:15 +0800 |
commit | 80bd5f27b72a5f11b67f4b36006b0f25627bc5d6 (patch) | |
tree | 06d56516f6cbb43a1c10548ecbc431d2b05cd51f /init.lua | |
parent | 60c81f7fb00626f27a02e7ca50375c229be3f778 (diff) | |
download | vis-pairs-master.tar.gz |
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -115,12 +115,22 @@ local function match_at(str, pattern, pos) if t then return t[1] - 1, t[#t] - 1 end end +--- Returns a unique grammar rule name for the given lexer's rule name. +local function rule_id(lexer, name) return lexer._name .. '.' .. name end + +-- get_rule that doesn't assert on me: +local function get_rule(lexer, id) + if lexer._lexer then lexer = lexer._lexer end -- proxy; get true parent + if id == 'whitespace' then return l.V(rule_id(lexer, id)) end -- special case + return (lexer._RULES or lexer._rules)[id] +end + local function escaping_context(lexer, range, data) - local rules = lexer._RULES local p for _, name in ipairs({vis.lexers.COMMENT, vis.lexers.STRING}) do - if rules[name] then - p = p and p + rules[name] / 0 or rules[name] / 0 + local rule = get_rule(lexer, name) + if rule then + p = p and p + rule / 0 or rule / 0 end end if not p then return {} end @@ -131,10 +141,11 @@ local function escaping_context(lexer, range, data) local escaped_range = {e1 + 1, e2} local escaped_data = data:sub(e1 + 1, e2) for _, level in ipairs({vis.lexers.COMMENT, vis.lexers.STRING}) do - if l.match(rules[level] / 0 * -1, escaped_data) then + if l.match(get_rule(lexer, level) / 0 * -1, escaped_data) then for _, name in ipairs(precedence[level]) do - if rules[name] then - p = p and p + rules[name] / 0 or rules[name] / 0 + local rule = get_rule(lexer, name) + if rule then + p = p and p + rule / 0 or rule / 0 end end return {escape = p, range = escaped_range} |