1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- CoffeeScript LPeg lexer.
4 local l
= require('lexer')
5 local token
, word_match
= l
.token
, l
.word_match
6 local P
, S
= lpeg
.P
, lpeg
.S
8 local M
= {_NAME
= 'coffeescript'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local block_comment
= '###' * (l
.any
- '###')^
0 * P('###')^
-1
15 local line_comment
= '#' * l
.nonnewline_esc^
0
16 local comment
= token(l
.COMMENT
, block_comment
+ line_comment
)
19 local sq_str
= l
.delimited_range("'")
20 local dq_str
= l
.delimited_range('"')
21 local regex_str
= #P('/') * l
.last_char_includes('+-*%<>!=^&|?~:;,([{') *
22 l
.delimited_range('/', true) * S('igm')^
0
23 local string = token(l
.STRING
, sq_str
+ dq_str
) + token(l
.REGEX
, regex_str
)
26 local number = token(l
.NUMBER
, l
.float
+ l
.integer
)
29 local keyword
= token(l
.KEYWORD
, word_match
{
30 'all', 'and', 'bind', 'break', 'by', 'case', 'catch', 'class', 'const',
31 'continue', 'default', 'delete', 'do', 'each', 'else', 'enum', 'export',
32 'extends', 'false', 'for', 'finally', 'function', 'if', 'import', 'in',
33 'instanceof', 'is', 'isnt', 'let', 'loop', 'native', 'new', 'no', 'not', 'of',
34 'off', 'on', 'or', 'return', 'super', 'switch', 'then', 'this', 'throw',
35 'true', 'try', 'typeof', 'unless', 'until', 'var', 'void', 'with', 'when',
39 -- Fields: object properties and methods.
40 local field
= token(l
.FUNCTION
, '.' * (S('_$') + l
.alpha
) *
41 (S('_$') + l
.alnum
)^
0)
44 local identifier
= token(l
.IDENTIFIER
, l
.word
)
47 local operator
= token(l
.OPERATOR
, S('+-/*%<>!=^&|?~:;,.()[]{}'))
53 {'identifier', identifier
},
57 {'operator', operator
},
60 M
._FOLDBYINDENTATION
= true