vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 3cfa1e9dfdee4f34725318fd63a96e3ec8429832
parent 57cb07df65c7832a448348d10c387a1ee04a1012
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sun,  2 Feb 2020 11:19:39 +0100

lexers: also apply 57cb07d to html and wsf lexers

Adapt in_tag to surrounding coding stlye and use the same simplified
version in html, wsf and xml lexers.

Diffstat:
Mlua/lexers/html.lua | 13+++----------
Mlua/lexers/wsf.lua | 8+-------
Mlua/lexers/xml.lua | 2+-
3 files changed, 5 insertions(+), 18 deletions(-)

diff --git a/lua/lexers/html.lua b/lua/lexers/html.lua @@ -21,18 +21,11 @@ local dq_str = l.delimited_range('"') local string = #S('\'"') * l.last_char_includes('=') * token(l.STRING, sq_str + dq_str) --- TODO: performance is terrible on large files. -local in_tag = P(function(input, index) - local before = input:sub(1, index - 1) - local s, e = before:find('<[^>]-$'), before:find('>[^<]-$') - if s and e then return s > e and index or nil end - if s then return index end - return input:find('^[^<]->', index) and index or nil -end) +local in_tag = #P((1 - S'><')^0 * '>') -- Numbers. local number = #l.digit * l.last_char_includes('=') * - token(l.NUMBER, l.digit^1 * P('%')^-1) --* in_tag + token(l.NUMBER, l.digit^1 * P('%')^-1) * in_tag -- Elements. local known_element = token('element', '<' * P('/')^-1 * word_match({ @@ -80,7 +73,7 @@ local attribute = (known_attribute + unknown_attribute) * #(l.space^0 * '=') local tag_close = token('element', P('/')^-1 * '>') -- Equals. -local equals = token(l.OPERATOR, '=') --* in_tag +local equals = token(l.OPERATOR, '=') * in_tag -- Entities. local entity = token('entity', '&' * (l.any - l.space - ';')^1 * ';') diff --git a/lua/lexers/wsf.lua b/lua/lexers/wsf.lua @@ -20,13 +20,7 @@ local dq_str = l.delimited_range('"', false, true) local string = #S('\'"') * l.last_char_includes('=') * token(l.STRING, sq_str + dq_str) -local in_tag = P(function(input, index) - local before = input:sub(1, index - 1) - local s, e = before:find('<[^>]-$'), before:find('>[^<]-$') - if s and e then return s > e and index or nil end - if s then return index end - return input:find('^[^<]->', index) and index or nil -end) +local in_tag = #P((1 - S'><')^0 * '>') -- Numbers. local number = #l.digit * l.last_char_includes('=') * diff --git a/lua/lexers/xml.lua b/lua/lexers/xml.lua @@ -20,7 +20,7 @@ local dq_str = l.delimited_range('"', false, true) local string = #S('\'"') * l.last_char_includes('=') * token(l.STRING, sq_str + dq_str) -local in_tag = #P((1 - S"><")^0 * ">") +local in_tag = #P((1 - S'><')^0 * '>') -- Numbers. local number = #l.digit * l.last_char_includes('=') *