travis: try to fix build by using local built dependencies
[vis.git] / lexers / javascript.lua
bloba9f469bf97f55fe585e51882714e9c206890bc41
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- JavaScript LPeg lexer.
4 local l = require('lexer')
5 local token, word_match = l.token, l.word_match
6 local P, R, S = lpeg.P, lpeg.R, lpeg.S
8 local M = {_NAME = 'javascript'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local line_comment = '//' * l.nonnewline_esc^0
15 local block_comment = '/*' * (l.any - '*/')^0 * P('*/')^-1
16 local comment = token(l.COMMENT, line_comment + block_comment)
18 -- Strings.
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)
25 -- Numbers.
26 local number = token(l.NUMBER, l.float + l.integer)
28 -- Keywords.
29 local keyword = token(l.KEYWORD, word_match{
30 'abstract', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class',
31 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'double', 'else',
32 'enum', 'export', 'extends', 'false', 'final', 'finally', 'float', 'for',
33 'function', 'goto', 'if', 'implements', 'import', 'in', 'instanceof', 'int',
34 'interface', 'let', 'long', 'native', 'new', 'null', 'package', 'private',
35 'protected', 'public', 'return', 'short', 'static', 'super', 'switch',
36 'synchronized', 'this', 'throw', 'throws', 'transient', 'true', 'try',
37 'typeof', 'var', 'void', 'volatile', 'while', 'with', 'yield'
40 -- Identifiers.
41 local identifier = token(l.IDENTIFIER, l.word)
43 -- Operators.
44 local operator = token(l.OPERATOR, S('+-/*%^!=&|?:;,.()[]{}<>'))
46 M._rules = {
47 {'whitespace', ws},
48 {'keyword', keyword},
49 {'identifier', identifier},
50 {'comment', comment},
51 {'number', number},
52 {'string', string},
53 {'operator', operator},
56 M._foldsymbols = {
57 _patterns = {'[{}]', '/%*', '%*/', '//'},
58 [l.OPERATOR] = {['{'] = 1, ['}'] = -1},
59 [l.COMMENT] = {['/*'] = 1, ['*/'] = -1, ['//'] = l.fold_line_comments('//')}
62 return M