import
[web.mtrack] / inc / hyperlight / php.php
1 <?php
2
3 // TODO
4 // - Fill the scaffold below!
5 // - More keywords? What about functions?
6 // - String interpolation and escaping.
7 // - Usual stuff for doc comments
8 // - Heredoc et al.
9 // - More complex nested variable names.
10
11 class PhpLanguage extends HyperLanguage {
12     public function __construct() {
13         $this->setInfo(array(
14             parent::NAME => 'PHP',
15             parent::VERSION => '0.3',
16             parent::AUTHOR => array(
17                 parent::NAME => 'Konrad Rudolph',
18                 parent::WEBSITE => 'madrat.net',
19                 parent::EMAIL => 'konrad_rudolph@madrat.net'
20             )
21         ));
22
23         $this->setExtensions(array('php', 'php3', 'php4', 'php5', 'inc'));
24
25         $this->addPostProcessing('html', HyperLanguage::fromName('xml'));
26
27         $this->addStates(array(
28             'init' => array('php', 'html'),
29             'php' => array(
30                 'comment', 'string', 'char', 'number',
31                 'keyword' => array('', 'type', 'literal', 'operator', 'builtin'),
32                 'identifier', 'variable'),
33             'variable' => array('identifier'),
34             'html' => array()
35         ));
36
37         $this->addRules(array(
38             'php' => new Rule('/<\?php/', '/\?>/'),
39             'html' => new Rule('/(?=.)/', '/(?=<\?php)/'),
40             'comment' => ",#[^\n]*\n|//.*?\n|/\*.*?\*/,s",
41             'string' => Rule::C_DOUBLEQUOTESTRING,
42             'char' => Rule::C_SINGLEQUOTESTRING,
43             'number' => Rule::C_NUMBER,
44             'identifier' => Rule::C_IDENTIFIER,
45             'variable' => new Rule('/\$/', '//'),
46             'keyword' => array(
47                 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'),
48                 'type' => array('exception', 'int'),
49                 'literal' => array('false', 'null', 'true', 'this'),
50                 'operator' => array('and', 'as', 'or', 'xor', 'new', 'instanceof', 'clone'),
51                 'builtin' => array('array', 'die', 'echo', 'empty', 'eval', 'exit', 'include', 'include_once', 'isset', 'list', 'print', 'require', 'require_once', 'unset')
52             ),
53         ));
54
55         $this->addMappings(array(
56             'char' => 'string',
57             'variable' => 'tag',
58             'html' => 'preprocessor',
59         ));
60     }
61 }
62
63 ?>