matlab.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * Matlab's pretty simple. Hoorah
  4. */
  5. class LuminousMATLABScanner extends LuminousSimpleScanner {
  6. // Comments can nest. This beats a PCRE recursive regex, because they are
  7. // pretty flimsy and crash/stack overflow easily
  8. function comment_override($matches) {
  9. $this->nestable_token('COMMENT', '/%\\{/', '/%\\}/');
  10. }
  11. function init() {
  12. // these can nest so we override this
  13. $this->add_pattern('COMMENT_ML', '/%\\{/');
  14. $this->add_pattern('COMMENT', '/%.*/');
  15. $this->add_pattern('IDENT', '/[a-z_]\w*/i');
  16. // stray single quotes are a unary operator when they're attached to
  17. // an identifier or return value, or something. so we're going to
  18. // use a lookbehind to exclude those
  19. $this->add_pattern('STRING',
  20. "/(?<![\w\)\]\}']) ' (?: [^']+ | '')* ($|')/x");
  21. $this->add_pattern('NUMERIC', LuminousTokenPresets::$NUM_HEX);
  22. $this->add_pattern('NUMERIC', LuminousTokenPresets::$NUM_REAL);
  23. $this->add_pattern('OPERATOR', "@[¬!%^&*\-+=~;:|<>,./?]+|'@");
  24. $this->overrides = array('COMMENT_ML' => array($this, 'comment_override'));
  25. include(dirname(__FILE__) . '/include/matlab_func_list.php');
  26. $this->add_identifier_mapping('KEYWORD', $luminous_matlab_keywords);
  27. $this->add_identifier_mapping('VALUE', $luminous_matlab_values);
  28. $this->add_identifier_mapping('FUNCTION', $luminous_matlab_functions);
  29. }
  30. public static function guess_language($src, $info) {
  31. $p = 0;
  32. // matlab comments are quite distinctive
  33. if (preg_match('/%\\{.*%\\}/s', $src)) $p += 0.25;
  34. return $p;
  35. }
  36. }