travis: try to fix build by using local built dependencies
[vis.git] / lexers / actionscript.lua
blob0aafe637d0d55d35df0354d660eff5cb5ec35dcf
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Actionscript 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 = 'actionscript'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local line_comment = '//' * l.nonnewline^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("'", true)
20 local dq_str = l.delimited_range('"', true)
21 local ml_str = '<![CDATA[' * (l.any - ']]>')^0 * ']]>'
22 local string = token(l.STRING, sq_str + dq_str + ml_str)
24 -- Numbers.
25 local number = token(l.NUMBER, (l.float + l.integer) * S('LlUuFf')^-2)
27 -- Keywords.
28 local keyword = token(l.KEYWORD, word_match{
29 'break', 'continue', 'delete', 'do', 'else', 'for', 'function', 'if', 'in',
30 'new', 'on', 'return', 'this', 'typeof', 'var', 'void', 'while', 'with',
31 'NaN', 'Infinity', 'false', 'null', 'true', 'undefined',
32 -- Reserved for future use.
33 'abstract', 'case', 'catch', 'class', 'const', 'debugger', 'default',
34 'export', 'extends', 'final', 'finally', 'goto', 'implements', 'import',
35 'instanceof', 'interface', 'native', 'package', 'private', 'Void',
36 'protected', 'public', 'dynamic', 'static', 'super', 'switch', 'synchonized',
37 'throw', 'throws', 'transient', 'try', 'volatile'
40 -- Types.
41 local type = token(l.TYPE, word_match{
42 'Array', 'Boolean', 'Color', 'Date', 'Function', 'Key', 'MovieClip', 'Math',
43 'Mouse', 'Number', 'Object', 'Selection', 'Sound', 'String', 'XML', 'XMLNode',
44 'XMLSocket',
45 -- Reserved for future use.
46 'boolean', 'byte', 'char', 'double', 'enum', 'float', 'int', 'long', 'short'
49 -- Identifiers.
50 local identifier = token(l.IDENTIFIER, l.word)
52 -- Operators.
53 local operator = token(l.OPERATOR, S('=!<>+-/*%&|^~.,;?()[]{}'))
55 M._rules = {
56 {'whitespace', ws},
57 {'keyword', keyword},
58 {'type', type},
59 {'identifier', identifier},
60 {'string', string},
61 {'comment', comment},
62 {'number', number},
63 {'operator', operator},
66 M._foldsymbols = {
67 _patterns = {'[{}]', '/%*', '%*/', '//', '<!%[CDATA%[', '%]%]>'},
68 [l.OPERATOR] = {['{'] = 1, ['}'] = -1},
69 [l.COMMENT] = {
70 ['/*'] = 1, ['*/'] = -1, ['//'] = l.fold_line_comments('//')
72 [l.STRING] = {['<![CDATA['] = 1, [']]>'] = -1}
75 return M