File: JavaScriptParser.php

package info (click to toggle)
dojo 1.10.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 97,980 kB
  • ctags: 10,348
  • sloc: php: 10,616; xml: 3,429; java: 3,098; sql: 928; sh: 484; pascal: 205; perl: 182; makefile: 77; python: 45; sed: 37; ruby: 10
file content (129 lines) | stat: -rw-r--r-- 3,342 bytes parent folder | download | duplicates (7)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php

require_once('Parser.php');
require_once('JavaScriptSymbol.php');

class JavaScriptParser extends Parser {
  protected $symbol_class = JavaScriptSymbol;

  protected function build() {
    $this->symbol(';');
    $this->symbol("\n");
    $this->symbol(',');
    $this->symbol(')');
    $this->symbol(']');
    $this->symbol('}');
    $this->symbol('else');
    $this->symbol('case');
    $this->symbol('default');
    $this->symbol('catch');
    $this->symbol('finally');

    $symbol = $this->symbol(':');
    $symbol->lbp = 'lbp_colon';
    $symbol->led = 'led_colon';

    $this->symbol('(end)');
    $this->symbol('(name)');

    $this->assignment('=')->led = 'led_equals';
    $this->assignment('+=');
    $this->assignment('-=');
    $this->assignment('*=');
    $this->assignment('/=');
    $this->assignment('%=');
    $this->assignment('<<=');
    $this->assignment('>>=');
    $this->assignment('>>>=');
    $this->assignment('&=');
    $this->assignment('^=');
    $this->assignment('|=');

    $this->infix('?:', 20);
    $this->infixr('||', 21);
    $this->infixr('&&', 22);
    $this->infix('|', 23);
    $this->infix('^', 24);
    $this->infix('&', 25);

    $this->infix('==', 30);
    $this->infix('!=', 30);
    $this->infix('===', 30);
    $this->infix('!==', 30);

    $this->infix('<', 40);
    $this->infix('<=', 40);
    $this->infix('>', 40);
    $this->infix('>=', 40);
    $this->infix('in', 40);
    $this->infix('instanceof', 40);

    $this->infix('<<', 45);
    $this->infix('>>', 45);
    $this->infix('>>>', 45);

    $this->infix('+', 50);
    $this->infix('-', 50);

    $this->infix('*', 60);
    $this->infix('/', 60);
    $this->infix('%', 60);

    // prefix is 70
    $this->prefix('!');
    $this->prefix('~');
    $this->prefix('+');
    $this->prefix('-');
    $this->prefix('typeof');
    $this->prefix('void');
    $this->prefix('delete');
    $this->prefix('throw');

    // crement is 75
    $symbol = $this->symbol('++');
    $symbol->lbp = 'lbp_crement';
    $symbol->led = 'led_crement';
    $symbol->nud = 'nud_crement';
    $symbol = $this->symbol('--');
    $symbol->lbp = 'lbp_crement';
    $symbol->led = 'led_crement';
    $symbol->nud = 'nud_crement';

    $this->infix('(', 80, 'led_parenthesis')->nud = 'nud_parenthesis';

    $this->infix('.', 85, 'led_period');
    $this->infix('[', 85, 'led_bracket');
    $this->prefix('new')->lbp = 85;

    // Non-defined stuff:

    $this->infix('?', 20, 'led_questionmark');

    $this->constant('true', TRUE);
    $this->constant('false', FALSE);
    $this->constant('null', 'null');
    $this->constant('undefined', NULL);
    $this->constant('arguments', 'arguments');

    $this->symbol('(literal)')->nud = 'nud_itself';

    $this->stmt('{', 'std_curly');
    $this->stmt('var', 'std_var');
    $this->stmt('do', 'std_do');
    $this->stmt('while', 'std_while');
    $this->stmt('for', 'std_for');
    $this->stmt('if', 'std_if');
    $this->stmt('switch', 'std_switch');
    $this->stmt('try', 'std_try');
    $this->stmt('break', 'std_break');
    $this->stmt('return', 'std_return');
    $this->stmt('function', 'nud_function');
    $this->prefix('function', 'nud_function');

    $symbol = $this->symbol('this');
    $symbol->nud = 'nud_this';

    $this->prefix('[', 'nud_bracket');
    $this->prefix('{', 'nud_curly');
  }
}