vim.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. // I can't find some formal definition of vimscript's grammar.
  3. // I'm pretty sure it's more complex than this, but, who knows.
  4. require_once(dirname(__FILE__) . '/include/vim_list.php');
  5. class LuminousVimScriptScanner extends LuminousSimpleScanner {
  6. public function string_override() {
  7. $comment = $this->bol();
  8. $this->skip_whitespace();
  9. assert($this->peek() === '"');
  10. if ($comment) {
  11. $this->record($this->scan("/.*/"), 'COMMENT');
  12. } else {
  13. if ($this->scan("/ \" (?> [^\n\"\\\\]+ | \\\\. )*$ /mx")) {
  14. $this->record($this->match(), 'COMMENT');
  15. }
  16. else {
  17. $m = $this->scan(LuminousTokenPresets::$DOUBLE_STR);
  18. assert($m !== null);
  19. $this->record($m, 'STRING');
  20. }
  21. }
  22. }
  23. static function comment_filter($token) {
  24. $token = LuminousUtils::escape_token($token);
  25. $str = &$token[1];
  26. // It pays to run the strpos checks first.
  27. if (strpos(substr($str, 1), '"') !== false)
  28. $str = preg_replace('/(?<!^)"(?>[^"]*)"/', "<STRING>$0</STRING>", $str);
  29. if (strpos($str, ':') !== false)
  30. $str = preg_replace('/(?<=^")((?>\W*))((?>[A-Z]\w+(?>(?>\s+\w+)*)))(:\s*)(.*)/',
  31. '$1<DOCTAG>$2</DOCTAG>$3<DOCSTR>$4</DOCSTR>', $str);
  32. return $token;
  33. }
  34. function init() {
  35. $this->add_pattern('COMMENT_STRING', "/[\t ]*\"/");
  36. $this->add_pattern('STRING', "/'(?>[^\n\\\\']+ | \\\\. )*'/x");
  37. $this->add_pattern('NUMERIC','/\#[a-f0-9]+/i');
  38. $this->add_pattern('NUMERIC', LuminousTokenPresets::$NUM_HEX);
  39. $this->add_pattern('NUMERIC', LuminousTokenPresets::$NUM_REAL);
  40. $this->add_pattern('IDENT', '/[a-z_]\w*/i');
  41. $this->add_pattern('OPERATOR', '@[~¬!%^&*\-=+;:,<.>/?\|]+@');
  42. $this->add_identifier_mapping('FUNCTION',
  43. $GLOBALS['luminous_vim_functions']);
  44. $this->add_identifier_mapping('KEYWORD',
  45. $GLOBALS['luminous_vim_keywords']);
  46. $this->remove_stream_filter('oo-syntax');
  47. $this->remove_filter('comment-to-doc');
  48. $this->add_filter('comment', 'COMMENT', array($this, 'comment_filter'));
  49. $this->overrides = array('COMMENT_STRING' => array($this, 'string_override'));
  50. }
  51. }