File: litcoffee.lua

package info (click to toggle)
vis 0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,624 kB
  • sloc: ansic: 23,195; sh: 981; makefile: 363; python: 47
file content (21 lines) | stat: -rw-r--r-- 766 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- Copyright 2006-2024 Robert Gieseke. See LICENSE.
-- Literate CoffeeScript LPeg lexer.
-- http://coffeescript.org/#literate

local lexer = require('lexer')
local token = lexer.token
local P, S = lpeg.P, lpeg.S

local lex = lexer.new('litcoffee', {inherit = lexer.load('markdown')})

-- 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)
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