forked from glayzzle/php-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripting.js
More file actions
100 lines (99 loc) · 2.83 KB
/
scripting.js
File metadata and controls
100 lines (99 loc) · 2.83 KB
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
/*!
* Copyright (C) 2017 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
module.exports = {
matchST_IN_SCRIPTING: function() {
var ch = this.input();
switch(ch) {
case ' ':
case '\t':
case '\n':
case '\r':
case '\r\n':
return this.T_WHITESPACE();
case '#':
return this.T_COMMENT();
case '/':
if (this._input[this.offset] === '/') {
return this.T_COMMENT();
} else if (this._input[this.offset] === '*') {
this.input();
return this.T_DOC_COMMENT();
}
return this.consume_TOKEN();
case '\'':
return this.T_CONSTANT_ENCAPSED_STRING();
case '"':
return this.ST_DOUBLE_QUOTES();
case '`':
this.begin('ST_BACKQUOTE');
return '`';
case '?':
if (!this.aspTagMode && this.tryMatch('>')) {
this.input();
var nextCH = this._input[this.offset];
if (nextCH === '\n' || nextCH === '\r') this.input();
if (this.conditionStack.length > 1) {
this.begin('INITIAL');
}
return this.tok.T_CLOSE_TAG;
}
return this.consume_TOKEN();
case '%':
if (this.aspTagMode && this._input[this.offset] === '>') {
this.input(); // consume the '>'
ch = this._input[this.offset]; // read next
if (ch === '\n' || ch === '\r') {
this.input(); // consume the newline
}
this.aspTagMode = false;
if (this.conditionStack.length > 1) {
this.begin('INITIAL');
}
return this.tok.T_CLOSE_TAG;
}
return this.consume_TOKEN();
case '{':
this.begin('ST_IN_SCRIPTING');
return '{';
case '}':
if (this.conditionStack.length > 2) {
// Return to HEREDOC/ST_DOUBLE_QUOTES mode
this.popState();
}
return '}';
default:
if (ch === '.') {
ch = this.input();
if (this.is_NUM()) {
return this.consume_NUM();
} else {
if (ch) this.unput(1);
}
}
if (this.is_NUM()) {
return this.consume_NUM();
} else if (this.is_LABEL_START()) {
return this.consume_LABEL().T_STRING();
} else if(this.is_TOKEN()) {
return this.consume_TOKEN();
}
}
throw new Error(
'Bad terminal sequence "' + ch + '" at line ' + this.yylineno + ' (offset ' + this.offset + ')'
);
},
T_WHITESPACE: function() {
while(this.offset < this.size) {
var ch = this.input();
if (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r') {
continue;
}
this.unput(1);
break;
}
return this.tok.T_WHITESPACE;
}
};