logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

actionscript.lua (2185B)


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