vis

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

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

litcoffee.lua

(712B)


      1 -- Copyright 2006-2025 Robert Gieseke. See LICENSE.
      2 -- Literate CoffeeScript LPeg lexer.
      3 -- http://coffeescript.org/#literate
      4 
      5 local lexer = lexer
      6 local P, S = lpeg.P, lpeg.S
      7 
      8 local lex = lexer.new(..., {inherit = lexer.load('markdown')})
      9 
     10 -- Distinguish between horizontal and vertical space so coffee_start_rule has a chance to match.
     11 lex:modify_rule('whitespace', lex:tag(lexer.WHITESPACE, S(' \t')^1 + S('\r\n')^1))
     12 
     13 -- Embedded CoffeeScript.
     14 local coffeescript = lexer.load('coffeescript')
     15 local coffee_start_rule = #(P(' ')^4 + P('\t')) * lex:get_rule('whitespace')
     16 local coffee_end_rule = #lexer.newline * lex:get_rule('whitespace')
     17 lex:embed(coffeescript, coffee_start_rule, coffee_end_rule)
     18 
     19 return lex