mtrack /inc/hyperlight/php.php

Language PHP Lines 64
MD5 Hash 8c93637600aa35e56a60351fe79e4c6d Estimated Cost $1,065 (why?)
Repository https://bitbucket.org/yoander/mtrack View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

// TODO
// - Fill the scaffold below!
// - More keywords? What about functions?
// - String interpolation and escaping.
// - Usual stuff for doc comments
// - Heredoc et al.
// - More complex nested variable names.

class PhpLanguage extends HyperLanguage {
    public function __construct() {
        $this->setInfo(array(
            parent::NAME => 'PHP',
            parent::VERSION => '0.3',
            parent::AUTHOR => array(
                parent::NAME => 'Konrad Rudolph',
                parent::WEBSITE => 'madrat.net',
                parent::EMAIL => 'konrad_rudolph@madrat.net'
            )
        ));

        $this->setExtensions(array('php', 'php3', 'php4', 'php5', 'inc'));

        $this->addPostProcessing('html', HyperLanguage::fromName('xml'));

        $this->addStates(array(
            'init' => array('php', 'html'),
            'php' => array(
                'comment', 'string', 'char', 'number',
                'keyword' => array('', 'type', 'literal', 'operator', 'builtin'),
                'identifier', 'variable'),
            'variable' => array('identifier'),
            'html' => array()
        ));

        $this->addRules(array(
            'php' => new Rule('/<\?php/', '/\?>/'),
            'html' => new Rule('/(?=.)/', '/(?=<\?php)/'),
            'comment' => ",#[^\n]*\n|//.*?\n|/\*.*?\*/,s",
            'string' => Rule::C_DOUBLEQUOTESTRING,
            'char' => Rule::C_SINGLEQUOTESTRING,
            'number' => Rule::C_NUMBER,
            'identifier' => Rule::C_IDENTIFIER,
            'variable' => new Rule('/\$/', '//'),
            'keyword' => array(
                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'),
                'type' => array('exception', 'int'),
                'literal' => array('false', 'null', 'true', 'this'),
                'operator' => array('and', 'as', 'or', 'xor', 'new', 'instanceof', 'clone'),
                'builtin' => array('array', 'die', 'echo', 'empty', 'eval', 'exit', 'include', 'include_once', 'isset', 'list', 'print', 'require', 'require_once', 'unset')
            ),
        ));

        $this->addMappings(array(
            'char' => 'string',
            'variable' => 'tag',
            'html' => 'preprocessor',
        ));
    }
}

?>
Back to Top