import
[web.mtrack] / inc / hyperlight / cpp.php
1 <?php
2
3 // TODO:
4 // - Add escaped string characters
5 // - Add 'TO DO', 'FIX ME', … tags
6 // - (Add doc comments?)
7
8 class CppLanguage extends HyperLanguage {
9     public function __construct() {
10         $this->setInfo(array(
11             parent::NAME => 'C++',
12             parent::VERSION => '0.4',
13             parent::AUTHOR => array(
14                 parent::NAME => 'Konrad Rudolph',
15                 parent::WEBSITE => 'madrat.net',
16                 parent::EMAIL => 'konrad_rudolph@madrat.net'
17             )
18         ));
19
20         $this->setExtensions(array('c', 'cc', 'cpp', 'h', 'hpp', 'icl', 'ipp'));
21
22         $keyword = array('keyword' => array('', 'type', 'literal', 'operator'));
23         $common = array(
24             'string', 'char', 'number', 'comment',
25             'keyword' => array('', 'type', 'literal', 'operator'),
26             'identifier',
27             'operator'
28         );
29
30         $this->addStates(array(
31             'init' => array_merge(array('include', 'preprocessor'), $common),
32             'include' => array('incpath'),
33             'preprocessor' => array_merge($common, array('pp_newline')),
34         ));
35
36         $this->addRules(array(
37             'whitespace' => RULE::ALL_WHITESPACE,
38             'operator' => '/<:|:>|<%|%>|%:|%:%:|\+\+|--|&&|\|\||::|<<|>>|##|\.\.\.|\.\*|->|->*|[-+*\/%^&|!~<>.=,;:?()\[\]\{\}]|[-+*\/%^&|=!~<>]=|<<=|>>=/',
39             'include' => new Rule('/#\s*include/', '/\n/'),
40             'preprocessor' => new Rule('/#\s*\w+/', '/\n/'),
41             //'pp_newline' => '/[^\\\\](?<bs>\\\\*?)(?P=bs)\\\\\n/',
42             'pp_newline' => '/(?<!\\\\)(?:\\\\\\\\)*?\\\\\n/',
43             'incpath' => '/<[^>]*>|"[^"]*"/',
44             'string' => Rule::C_DOUBLEQUOTESTRING,
45             'char' => Rule::C_SINGLEQUOTESTRING,
46             'number' => Rule::C_NUMBER,
47             'comment' => Rule::C_COMMENT,
48             'keyword' => array(
49                 array(
50                     'asm', 'auto', 'break', 'case', 'catch', 
51                     'const_cast', 'continue', 'default', 'do', 'dynamic_cast',
52                     'else', 'explicit', 'export', 'extern', 'for',
53                     'friend', 'goto', 'if', 'mutable', 'namespace',
54                     'operator', 'private', 'protected', 'public', 'register',
55                     'reinterpret_cast', 'return', 'sizeof',
56                     'static_cast', 'switch', 'template', 'throw',
57                     'try', 'typedef', 'typename', 'using', 'virtual',
58                     'volatile', 'while'
59                 ),
60                 'type' => array(
61                     'bool', 'char', 'double', 'float', 'int', 'long', 'short',
62                     'signed', 'unsigned', 'void', 'wchar_t', 'struct', 'union',
63                                                                                 'class', 'static', 'inline', 'enum', 'const',
64                                                                                 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t',
65                                                                                 'int8_t', 'int16_t', 'int32_t', 'int64_t', 'FILE', 'DIR',
66                 ),
67                 'literal' => array(
68                     'false', 'this', 'true', 'NULL',
69                 ),
70                 'operator' => array(
71                     'and', 'and_eq', 'bitand', 'bitor', 'compl', 'delete',
72                     'new', 'not', 'not_eq', 'or', 'or_eq', 'typeid', 'xor',
73                     'xor_eq'
74                 ),
75             ),
76             'identifier' => Rule::C_IDENTIFIER,
77         ));
78
79         $this->addMappings(array(
80             'operator' => '',
81             'include' => 'preprocessor',
82             'incpath' => 'tag',
83         ));
84     }
85 }
86
87 ?>