summaryrefslogtreecommitdiffstats
path: root/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua23
1 files changed, 17 insertions, 6 deletions
diff --git a/init.lua b/init.lua
index 1c8cda7..27cf638 100644
--- a/init.lua
+++ b/init.lua
@@ -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}