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'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
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
)
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
)
25 local number = token(l
.NUMBER
, (l
.float
+ l
.integer
) * S('LlUuFf')^
-2)
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'
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',
45 -- Reserved for future use.
46 'boolean', 'byte', 'char', 'double', 'enum', 'float', 'int', 'long', 'short'
50 local identifier
= token(l
.IDENTIFIER
, l
.word
)
53 local operator
= token(l
.OPERATOR
, S('=!<>+-/*%&|^~.,;?()[]{}'))
59 {'identifier', identifier
},
63 {'operator', operator
},
67 _patterns
= {'[{}]', '/%*', '%*/', '//', '<!%[CDATA%[', '%]%]>'},
68 [l
.OPERATOR
] = {['{'] = 1, ['}'] = -1},
70 ['/*'] = 1, ['*/'] = -1, ['//'] = l
.fold_line_comments('//')
72 [l
.STRING
] = {['<![CDATA['] = 1, [']]>'] = -1}