PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/hyperlight/php.php

https://bitbucket.org/yoander/mtrack
PHP | 63 lines | 48 code | 8 blank | 7 comment | 0 complexity | 8c93637600aa35e56a60351fe79e4c6d MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. <?php
  2. // TODO
  3. // - Fill the scaffold below!
  4. // - More keywords? What about functions?
  5. // - String interpolation and escaping.
  6. // - Usual stuff for doc comments
  7. // - Heredoc et al.
  8. // - More complex nested variable names.
  9. class PhpLanguage extends HyperLanguage {
  10. public function __construct() {
  11. $this->setInfo(array(
  12. parent::NAME => 'PHP',
  13. parent::VERSION => '0.3',
  14. parent::AUTHOR => array(
  15. parent::NAME => 'Konrad Rudolph',
  16. parent::WEBSITE => 'madrat.net',
  17. parent::EMAIL => 'konrad_rudolph@madrat.net'
  18. )
  19. ));
  20. $this->setExtensions(array('php', 'php3', 'php4', 'php5', 'inc'));
  21. $this->addPostProcessing('html', HyperLanguage::fromName('xml'));
  22. $this->addStates(array(
  23. 'init' => array('php', 'html'),
  24. 'php' => array(
  25. 'comment', 'string', 'char', 'number',
  26. 'keyword' => array('', 'type', 'literal', 'operator', 'builtin'),
  27. 'identifier', 'variable'),
  28. 'variable' => array('identifier'),
  29. 'html' => array()
  30. ));
  31. $this->addRules(array(
  32. 'php' => new Rule('/<\?php/', '/\?>/'),
  33. 'html' => new Rule('/(?=.)/', '/(?=<\?php)/'),
  34. 'comment' => ",#[^\n]*\n|//.*?\n|/\*.*?\*/,s",
  35. 'string' => Rule::C_DOUBLEQUOTESTRING,
  36. 'char' => Rule::C_SINGLEQUOTESTRING,
  37. 'number' => Rule::C_NUMBER,
  38. 'identifier' => Rule::C_IDENTIFIER,
  39. 'variable' => new Rule('/\$/', '//'),
  40. 'keyword' => array(
  41. array('break', 'case', 'class', 'const', 'continue', 'declare', 'default', 'do', 'else', 'elseif', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'extends', 'for', 'foreach', 'function', 'global', 'if', 'return', 'static', 'switch', 'use', 'var', 'while', 'final', 'interface', 'implements', 'public', 'private', 'protected', 'abstract', 'try', 'catch', 'throw', 'final', 'namespace'),
  42. 'type' => array('exception', 'int'),
  43. 'literal' => array('false', 'null', 'true', 'this'),
  44. 'operator' => array('and', 'as', 'or', 'xor', 'new', 'instanceof', 'clone'),
  45. 'builtin' => array('array', 'die', 'echo', 'empty', 'eval', 'exit', 'include', 'include_once', 'isset', 'list', 'print', 'require', 'require_once', 'unset')
  46. ),
  47. ));
  48. $this->addMappings(array(
  49. 'char' => 'string',
  50. 'variable' => 'tag',
  51. 'html' => 'preprocessor',
  52. ));
  53. }
  54. }
  55. ?>