vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

actionscript.lua

(2173B)


      1 -- Copyright 2006-2025 Mitchell. See LICENSE.
      2 -- Actionscript LPeg lexer.
      3 
      4 local lexer = require('lexer')
      5 local token, word_match = lexer.token, lexer.word_match
      6 local P, S = lpeg.P, lpeg.S
      7 
      8 local lex = lexer.new('actionscript')
      9 
     10 -- Whitespace.
     11 lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
     12 
     13 -- Keywords.
     14 lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
     15 	'break', 'continue', 'delete', 'do', 'else', 'for', 'function', 'if', 'in', 'new', 'on', 'return',
     16 	'this', 'typeof', 'var', 'void', 'while', 'with', 'NaN', 'Infinity', 'false', 'null', 'true',
     17 	'undefined',
     18 	-- Reserved for future use.
     19 	'abstract', 'case', 'catch', 'class', 'const', 'debugger', 'default', 'export', 'extends',
     20 	'final', 'finally', 'goto', 'implements', 'import', 'instanceof', 'interface', 'native',
     21 	'package', 'private', 'Void', 'protected', 'public', 'dynamic', 'static', 'super', 'switch',
     22 	'synchonized', 'throw', 'throws', 'transient', 'try', 'volatile'
     23 }))
     24 
     25 -- Types.
     26 lex:add_rule('type', token(lexer.TYPE, word_match{
     27 	'Array', 'Boolean', 'Color', 'Date', 'Function', 'Key', 'MovieClip', 'Math', 'Mouse', 'Number',
     28 	'Object', 'Selection', 'Sound', 'String', 'XML', 'XMLNode', 'XMLSocket',
     29 	-- Reserved for future use.
     30 	'boolean', 'byte', 'char', 'double', 'enum', 'float', 'int', 'long', 'short'
     31 }))
     32 
     33 -- Identifiers.
     34 lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
     35 
     36 -- Strings.
     37 local sq_str = lexer.range("'", true)
     38 local dq_str = lexer.range('"', true)
     39 local ml_str = lexer.range('<![CDATA[', ']]>')
     40 lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + ml_str))
     41 
     42 -- Comments.
     43 local line_comment = lexer.to_eol('//')
     44 local block_comment = lexer.range('/*', '*/')
     45 lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
     46 
     47 -- Numbers.
     48 lex:add_rule('number', token(lexer.NUMBER, lexer.number * S('LlUuFf')^-2))
     49 
     50 -- Operators.
     51 lex:add_rule('operator', token(lexer.OPERATOR, S('=!<>+-/*%&|^~.,;?()[]{}')))
     52 
     53 -- Fold points.
     54 lex:add_fold_point(lexer.OPERATOR, '{', '}')
     55 lex:add_fold_point(lexer.COMMENT, '/*', '*/')
     56 lex:add_fold_point(lexer.STRING, '<![CDATA[', ']]>')
     57 
     58 lexer.property['scintillua.comment'] = '//'
     59 
     60 return lex