as.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // as far as I know, actionscript and javascript are both derivatives of
  3. // ECMA script, and therefore we can subclass JavaScript's scanner and just
  4. // and override the identifier names.
  5. // but we also override init so as to prevent any embedding
  6. class LuminousActionScriptScanner extends LuminousECMAScriptScanner {
  7. function init() {
  8. $this->embedded_server = false;
  9. $this->embedded_script = false;
  10. parent::init();
  11. // add preprocessor support
  12. $this->add_pattern('PREPROCESSOR', '/\^\s*#.*/m');
  13. // clear the identifier map for JS and insert our own.
  14. // $this->ident_map = array();
  15. $this->add_identifier_mapping('', array());
  16. $this->add_identifier_mapping('FUNCTION', array('add', 'chr',
  17. 'clearInterval', 'escape', 'eval',
  18. 'evaluate', 'fscommand', 'getProperty', 'getTimer', 'getVersion',
  19. 'globalStyleFormat', 'gotoAndPlay', 'gotoAndStop', 'ifFrameLoaded',
  20. 'instanceOf', 'isFinite', 'isNaN', 'loadMovie', 'loadMovieNum',
  21. 'loadVariables', 'mbchr', 'mblength', 'mbord', 'mbsubstring', 'nextFrame',
  22. 'nextScene', 'onClipEvent',
  23. 'ord', 'parseFloat', 'parseInt', 'play', 'prevFrame', 'prevScene', 'print',
  24. 'printAsBitMap', 'printNum', 'printNum', 'random', 'scroll', 'setInterval',
  25. 'setProperty', 'stop', 'stopDrag', 'substring', 'super', 'targetPath',
  26. 'tellTarget', 'toString', 'toggleHighQuality', 'trace', 'unescape'));
  27. $this->add_identifier_mapping('TYPE', array('Accessibility',
  28. 'Array', 'Arguments', 'Boolean',
  29. 'Button', 'ByteArray', 'Camera', 'Color', 'Date', 'Event', 'FScrollPane',
  30. 'FStyleFormat',
  31. 'Function', 'int', 'Key', 'LoadVars', 'LocalConnection', 'Math',
  32. 'Microphone', 'Mouse', 'Movieclip', 'Number', 'Object', 'Selection',
  33. 'Sound', 'Sprite', 'String', 'System', 'TextField', 'TextFormat',
  34. 'Timer', 'TimerEvent', 'uint', 'var', 'void', 'XML'));
  35. $this->add_identifier_mapping('KEYWORD', array('as', 'break',
  36. 'case', 'catch', 'class', 'const', 'continue', 'default', 'delete',
  37. 'do', 'else', 'extends', 'false', 'finally', 'for', 'function',
  38. 'if', 'implements', 'import', 'in', 'instanceof', 'interface', 'internal',
  39. 'is', 'native', 'new', 'null', 'package', 'private', 'protected', 'public',
  40. 'return', 'super', 'switch', 'static', 'this', 'throw', 'to', 'true', 'try',
  41. 'typeof', 'use', 'void', 'while', 'with'));
  42. }
  43. public static function guess_language($src, $info) {
  44. // actionscript looks a lot like a cross between Java and, umm, well,
  45. // Java.
  46. // It has a semi-unique way of declaring types for arguments and
  47. // returns and so forth as argname:type, or function name(args):ret-type
  48. $p = 0.0;
  49. if (preg_match(
  50. '/\\bfunction\s+\w+\s*\\([^\\)]+\\):(String|int|Number|void)/',
  51. $src)) $p += 0.15;
  52. if (preg_match('/\\bvar\s+\w+:(String|int|Number)/', $src)) $p += 0.15;
  53. return $p;
  54. }
  55. }