vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit f270f176e813c5fafe0a62ef51fd3f6ed8bc67ae parent 4fa8fbcf2d1fa4e693134e4c9f5741f5181fc80a Author: orbitalquark <70453897+orbitalquark@users.noreply.github.com> Date: Wed, 18 Sep 2024 13:33:23 -0400 Migrate Literate Coffeescript lexer Diffstat:
| M | lua/lexers/litcoffee.lua | | | 16 | +++++++--------- |
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/lua/lexers/litcoffee.lua b/lua/lexers/litcoffee.lua @@ -2,20 +2,18 @@ -- Literate CoffeeScript LPeg lexer. -- http://coffeescript.org/#literate -local lexer = require('lexer') -local token = lexer.token +local lexer = lexer local P, S = lpeg.P, lpeg.S -local lex = lexer.new('litcoffee', {inherit = lexer.load('markdown')}) +local lex = lexer.new(..., {inherit = lexer.load('markdown')}) + +-- Distinguish between horizontal and vertical space so coffee_start_rule has a chance to match. +lex:modify_rule('whitespace', lex:tag(lexer.WHITESPACE, S(' \t')^1 + S('\r\n')^1)) -- Embedded CoffeeScript. local coffeescript = lexer.load('coffeescript') -local coffee_start_rule = token(lexer.EMBEDDED, (P(' ')^4 + P('\t'))) -local coffee_end_rule = token(lexer.EMBEDDED, lexer.newline) +local coffee_start_rule = #(P(' ')^4 + P('\t')) * lex:get_rule('whitespace') +local coffee_end_rule = #lexer.newline * lex:get_rule('whitespace') lex:embed(coffeescript, coffee_start_rule, coffee_end_rule) --- Use 'markdown_whitespace' instead of lexer.WHITESPACE since the latter would expand to --- 'litcoffee_whitespace'. -lex:modify_rule('whitespace', token('markdown_whitespace', S(' \t')^1 + S('\r\n')^1)) - return lex