import
[web.mtrack] / inc / hyperlight / javascript.php
1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3
4 class JavascriptLanguage extends HyperLanguage {
5   public function __construct() {
6     $this->setInfo(array(
7           parent::NAME => 'Javascript',
8           ));
9     $this->setExtensions(array('js', 'json'));
10     $this->setCaseInsensitive(false);
11     $this->addStates(array(
12           'init' => array(
13             'string',
14             'char',
15             'number',
16             'comment',
17             'keyword' => array('', 'literal', 'operator'),
18             'identifier'
19             ),
20           ));
21
22     $this->addRules(array(
23           'string' => Rule::C_DOUBLEQUOTESTRING,
24           'char' => Rule::C_SINGLEQUOTESTRING,
25           'number' => Rule::C_NUMBER,
26           'comment' => Rule::C_COMMENT,
27           'keyword' => array(
28             array(
29               'assert', 'break', 'class', 'continue',
30               'else', 'except', 'finally', 'for',
31               'if', 'in', 'function',
32               'throw', 'return', 'try', 'while', 'with', 'typeof'
33               ),
34             'literal' => array(
35               'false', 'null', 'true'
36               ),
37             'operator' => '/[-+*\/%&|^!~=<>?{}()\[\].,:;]|&&|\|\||<<|>>|[-=!<>+*\/%&|^]=|<<=|>>=|->/',
38             ),
39           'identifier' => Rule::C_IDENTIFIER,
40           ));
41         $this->addMappings(array(
42             'char' => 'string',
43         ));
44
45   }
46 }