@jorgsowa/php-parser 3.2.5-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +27 -0
- package/README.md +108 -0
- package/dist/@jorgsowa/php-parser.js +11239 -0
- package/dist/@jorgsowa/php-parser.min.js +2 -0
- package/dist/@jorgsowa/php-parser.min.js.LICENSE.txt +10 -0
- package/package.json +86 -0
- package/src/ast/array.js +44 -0
- package/src/ast/arrowfunc.js +43 -0
- package/src/ast/assign.js +28 -0
- package/src/ast/assignref.js +27 -0
- package/src/ast/attrgroup.js +21 -0
- package/src/ast/attribute.js +26 -0
- package/src/ast/bin.js +27 -0
- package/src/ast/block.js +24 -0
- package/src/ast/boolean.js +23 -0
- package/src/ast/break.js +21 -0
- package/src/ast/byref.js +21 -0
- package/src/ast/call.js +26 -0
- package/src/ast/case.js +26 -0
- package/src/ast/cast.js +28 -0
- package/src/ast/catch.js +29 -0
- package/src/ast/class.js +36 -0
- package/src/ast/classconstant.js +71 -0
- package/src/ast/clone.js +21 -0
- package/src/ast/closure.js +47 -0
- package/src/ast/comment.js +23 -0
- package/src/ast/commentblock.js +22 -0
- package/src/ast/commentline.js +22 -0
- package/src/ast/constant.js +26 -0
- package/src/ast/constantstatement.js +24 -0
- package/src/ast/continue.js +24 -0
- package/src/ast/declaration.js +60 -0
- package/src/ast/declare.js +71 -0
- package/src/ast/declaredirective.js +26 -0
- package/src/ast/do.js +26 -0
- package/src/ast/echo.js +26 -0
- package/src/ast/empty.js +23 -0
- package/src/ast/encapsed.js +75 -0
- package/src/ast/encapsedpart.js +28 -0
- package/src/ast/entry.js +30 -0
- package/src/ast/enum.js +30 -0
- package/src/ast/enumcase.js +26 -0
- package/src/ast/error.js +30 -0
- package/src/ast/eval.js +24 -0
- package/src/ast/exit.js +26 -0
- package/src/ast/expression.js +20 -0
- package/src/ast/expressionstatement.js +24 -0
- package/src/ast/for.js +33 -0
- package/src/ast/foreach.js +33 -0
- package/src/ast/function.js +34 -0
- package/src/ast/global.js +24 -0
- package/src/ast/goto.js +22 -0
- package/src/ast/halt.js +22 -0
- package/src/ast/identifier.js +26 -0
- package/src/ast/if.js +30 -0
- package/src/ast/include.js +28 -0
- package/src/ast/inline.js +23 -0
- package/src/ast/interface.js +28 -0
- package/src/ast/intersectiontype.js +24 -0
- package/src/ast/isset.js +23 -0
- package/src/ast/label.js +21 -0
- package/src/ast/list.js +26 -0
- package/src/ast/literal.js +28 -0
- package/src/ast/location.js +22 -0
- package/src/ast/lookup.js +26 -0
- package/src/ast/magic.js +22 -0
- package/src/ast/match.js +26 -0
- package/src/ast/matcharm.js +26 -0
- package/src/ast/method.js +24 -0
- package/src/ast/name.js +55 -0
- package/src/ast/namedargument.js +27 -0
- package/src/ast/namespace.js +26 -0
- package/src/ast/new.js +26 -0
- package/src/ast/node.js +111 -0
- package/src/ast/noop.js +20 -0
- package/src/ast/nowdoc.js +26 -0
- package/src/ast/nullkeyword.js +20 -0
- package/src/ast/nullsafepropertylookup.js +22 -0
- package/src/ast/number.js +23 -0
- package/src/ast/offsetlookup.js +22 -0
- package/src/ast/operation.js +19 -0
- package/src/ast/parameter.js +61 -0
- package/src/ast/parentreference.js +24 -0
- package/src/ast/position.js +22 -0
- package/src/ast/post.js +26 -0
- package/src/ast/pre.js +26 -0
- package/src/ast/print.js +23 -0
- package/src/ast/program.js +32 -0
- package/src/ast/property.js +46 -0
- package/src/ast/propertyhook.js +33 -0
- package/src/ast/propertylookup.js +22 -0
- package/src/ast/propertystatement.js +59 -0
- package/src/ast/reference.js +21 -0
- package/src/ast/retif.js +28 -0
- package/src/ast/return.js +21 -0
- package/src/ast/selfreference.js +24 -0
- package/src/ast/silent.js +24 -0
- package/src/ast/statement.js +19 -0
- package/src/ast/static.js +24 -0
- package/src/ast/staticlookup.js +22 -0
- package/src/ast/staticreference.js +24 -0
- package/src/ast/staticvariable.js +26 -0
- package/src/ast/string.js +28 -0
- package/src/ast/switch.js +28 -0
- package/src/ast/throw.js +21 -0
- package/src/ast/trait.js +24 -0
- package/src/ast/traitalias.js +44 -0
- package/src/ast/traitprecedence.js +28 -0
- package/src/ast/traituse.js +26 -0
- package/src/ast/try.js +28 -0
- package/src/ast/typereference.js +40 -0
- package/src/ast/unary.js +26 -0
- package/src/ast/uniontype.js +24 -0
- package/src/ast/unset.js +23 -0
- package/src/ast/usegroup.js +30 -0
- package/src/ast/useitem.js +45 -0
- package/src/ast/variable.js +36 -0
- package/src/ast/variadic.js +25 -0
- package/src/ast/variadicplaceholder.js +24 -0
- package/src/ast/while.js +28 -0
- package/src/ast/yield.js +27 -0
- package/src/ast/yieldfrom.js +25 -0
- package/src/ast.js +593 -0
- package/src/index.js +239 -0
- package/src/lexer/attribute.js +85 -0
- package/src/lexer/comments.js +63 -0
- package/src/lexer/initial.js +64 -0
- package/src/lexer/numbers.js +171 -0
- package/src/lexer/property.js +96 -0
- package/src/lexer/scripting.js +114 -0
- package/src/lexer/strings.js +524 -0
- package/src/lexer/tokens.js +356 -0
- package/src/lexer/utils.js +112 -0
- package/src/lexer.js +561 -0
- package/src/parser/array.js +113 -0
- package/src/parser/class.js +718 -0
- package/src/parser/comment.js +52 -0
- package/src/parser/enum.js +56 -0
- package/src/parser/expr.js +848 -0
- package/src/parser/function.js +507 -0
- package/src/parser/if.js +94 -0
- package/src/parser/loops.js +168 -0
- package/src/parser/main.js +21 -0
- package/src/parser/namespace.js +231 -0
- package/src/parser/scalar.js +492 -0
- package/src/parser/statement.js +444 -0
- package/src/parser/switch.js +99 -0
- package/src/parser/try.js +43 -0
- package/src/parser/utils.js +203 -0
- package/src/parser/variable.js +363 -0
- package/src/parser.js +748 -0
- package/src/tokens.js +177 -0
- package/types.d.ts +1457 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2018 Glayzzle (BSD3 License)
|
|
3
|
+
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
|
|
4
|
+
* @url http://glayzzle.com
|
|
5
|
+
*/
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
T_STRING() {
|
|
10
|
+
const token = this.yytext.toLowerCase();
|
|
11
|
+
let id = this.keywords[token];
|
|
12
|
+
if (typeof id !== "number") {
|
|
13
|
+
if (token === "yield") {
|
|
14
|
+
if (this.version >= 700 && this.tryMatch(" from")) {
|
|
15
|
+
this.consume(5);
|
|
16
|
+
id = this.tok.T_YIELD_FROM;
|
|
17
|
+
} else {
|
|
18
|
+
id = this.tok.T_YIELD;
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
id = this.tok.T_STRING;
|
|
22
|
+
if (token === "b" || token === "B") {
|
|
23
|
+
const ch = this.input();
|
|
24
|
+
if (ch === '"') {
|
|
25
|
+
return this.ST_DOUBLE_QUOTES();
|
|
26
|
+
} else if (ch === "'") {
|
|
27
|
+
return this.T_CONSTANT_ENCAPSED_STRING();
|
|
28
|
+
} else if (ch) {
|
|
29
|
+
this.unput(1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// https://github.com/php/php-src/blob/master/Zend/zend_language_scanner.l#L1546
|
|
36
|
+
if (id === this.tok.T_ENUM) {
|
|
37
|
+
if (this.version < 801) {
|
|
38
|
+
return this.tok.T_STRING;
|
|
39
|
+
}
|
|
40
|
+
const initial = this.offset;
|
|
41
|
+
let ch = this.input();
|
|
42
|
+
while (ch == " ") {
|
|
43
|
+
ch = this.input();
|
|
44
|
+
}
|
|
45
|
+
let isEnum = false;
|
|
46
|
+
if (this.is_LABEL_START()) {
|
|
47
|
+
while (this.is_LABEL()) {
|
|
48
|
+
ch += this.input();
|
|
49
|
+
}
|
|
50
|
+
const label = ch.slice(0, -1).toLowerCase();
|
|
51
|
+
isEnum = label !== "extends" && label !== "implements";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.unput(this.offset - initial);
|
|
55
|
+
return isEnum ? this.tok.T_ENUM : this.tok.T_STRING;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (this.offset < this.size && id !== this.tok.T_YIELD_FROM) {
|
|
59
|
+
// If immediately followed by a backslash, this is a T_NAME_RELATIVE or T_NAME_QUALIFIED.
|
|
60
|
+
let ch = this.input();
|
|
61
|
+
if (ch === "\\") {
|
|
62
|
+
id =
|
|
63
|
+
token === "namespace"
|
|
64
|
+
? this.tok.T_NAME_RELATIVE
|
|
65
|
+
: this.tok.T_NAME_QUALIFIED;
|
|
66
|
+
do {
|
|
67
|
+
if (this._input[this.offset] === "{") {
|
|
68
|
+
// e.g. when using group use statements, the last '\\' is followed by a '{'
|
|
69
|
+
this.input();
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.consume_LABEL();
|
|
74
|
+
ch = this.input();
|
|
75
|
+
} while (ch === "\\");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (ch) {
|
|
79
|
+
this.unput(1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return id;
|
|
84
|
+
},
|
|
85
|
+
// reads a custom token
|
|
86
|
+
consume_TOKEN() {
|
|
87
|
+
const ch = this._input[this.offset - 1];
|
|
88
|
+
const fn = this.tokenTerminals[ch];
|
|
89
|
+
if (fn) {
|
|
90
|
+
return fn.apply(this, []);
|
|
91
|
+
} else {
|
|
92
|
+
return this.yytext;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
// list of special char tokens
|
|
96
|
+
tokenTerminals: {
|
|
97
|
+
$() {
|
|
98
|
+
this.offset++;
|
|
99
|
+
if (this.is_LABEL_START()) {
|
|
100
|
+
this.offset--;
|
|
101
|
+
this.consume_LABEL();
|
|
102
|
+
return this.tok.T_VARIABLE;
|
|
103
|
+
} else {
|
|
104
|
+
this.offset--;
|
|
105
|
+
return "$";
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"-"() {
|
|
109
|
+
const nchar = this._input[this.offset];
|
|
110
|
+
if (nchar === ">") {
|
|
111
|
+
this.begin("ST_LOOKING_FOR_PROPERTY").input();
|
|
112
|
+
return this.tok.T_OBJECT_OPERATOR;
|
|
113
|
+
} else if (nchar === "-") {
|
|
114
|
+
this.input();
|
|
115
|
+
return this.tok.T_DEC;
|
|
116
|
+
} else if (nchar === "=") {
|
|
117
|
+
this.input();
|
|
118
|
+
return this.tok.T_MINUS_EQUAL;
|
|
119
|
+
}
|
|
120
|
+
return "-";
|
|
121
|
+
},
|
|
122
|
+
"\\"() {
|
|
123
|
+
if (this.offset < this.size) {
|
|
124
|
+
this.input();
|
|
125
|
+
if (this.is_LABEL_START()) {
|
|
126
|
+
let ch;
|
|
127
|
+
do {
|
|
128
|
+
if (this._input[this.offset] === "{") {
|
|
129
|
+
// e.g. when using group use statements, the last '\\' is followed by a '{'
|
|
130
|
+
this.input();
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this.consume_LABEL();
|
|
135
|
+
ch = this.input();
|
|
136
|
+
} while (ch === "\\");
|
|
137
|
+
|
|
138
|
+
this.unput(1);
|
|
139
|
+
|
|
140
|
+
return this.tok.T_NAME_FULLY_QUALIFIED;
|
|
141
|
+
} else {
|
|
142
|
+
this.unput(1);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return this.tok.T_NS_SEPARATOR;
|
|
146
|
+
},
|
|
147
|
+
"/"() {
|
|
148
|
+
if (this._input[this.offset] === "=") {
|
|
149
|
+
this.input();
|
|
150
|
+
return this.tok.T_DIV_EQUAL;
|
|
151
|
+
}
|
|
152
|
+
return "/";
|
|
153
|
+
},
|
|
154
|
+
":"() {
|
|
155
|
+
if (this._input[this.offset] === ":") {
|
|
156
|
+
this.input();
|
|
157
|
+
return this.tok.T_DOUBLE_COLON;
|
|
158
|
+
} else {
|
|
159
|
+
return ":";
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
"("() {
|
|
163
|
+
const initial = this.offset;
|
|
164
|
+
this.input();
|
|
165
|
+
if (this.is_TABSPACE()) {
|
|
166
|
+
this.consume_TABSPACE().input();
|
|
167
|
+
}
|
|
168
|
+
if (this.is_LABEL_START()) {
|
|
169
|
+
const yylen = this.yytext.length;
|
|
170
|
+
this.consume_LABEL();
|
|
171
|
+
const castToken = this.yytext.substring(yylen - 1).toLowerCase();
|
|
172
|
+
const castId = this.castKeywords[castToken];
|
|
173
|
+
if (typeof castId === "number") {
|
|
174
|
+
this.input();
|
|
175
|
+
if (this.is_TABSPACE()) {
|
|
176
|
+
this.consume_TABSPACE().input();
|
|
177
|
+
}
|
|
178
|
+
if (this._input[this.offset - 1] === ")") {
|
|
179
|
+
return castId;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// revert the check
|
|
184
|
+
this.unput(this.offset - initial);
|
|
185
|
+
return "(";
|
|
186
|
+
},
|
|
187
|
+
"="() {
|
|
188
|
+
const nchar = this._input[this.offset];
|
|
189
|
+
if (nchar === ">") {
|
|
190
|
+
this.input();
|
|
191
|
+
return this.tok.T_DOUBLE_ARROW;
|
|
192
|
+
} else if (nchar === "=") {
|
|
193
|
+
if (this._input[this.offset + 1] === "=") {
|
|
194
|
+
this.consume(2);
|
|
195
|
+
return this.tok.T_IS_IDENTICAL;
|
|
196
|
+
} else {
|
|
197
|
+
this.input();
|
|
198
|
+
return this.tok.T_IS_EQUAL;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return "=";
|
|
202
|
+
},
|
|
203
|
+
"+"() {
|
|
204
|
+
const nchar = this._input[this.offset];
|
|
205
|
+
if (nchar === "+") {
|
|
206
|
+
this.input();
|
|
207
|
+
return this.tok.T_INC;
|
|
208
|
+
} else if (nchar === "=") {
|
|
209
|
+
this.input();
|
|
210
|
+
return this.tok.T_PLUS_EQUAL;
|
|
211
|
+
}
|
|
212
|
+
return "+";
|
|
213
|
+
},
|
|
214
|
+
"!"() {
|
|
215
|
+
if (this._input[this.offset] === "=") {
|
|
216
|
+
if (this._input[this.offset + 1] === "=") {
|
|
217
|
+
this.consume(2);
|
|
218
|
+
return this.tok.T_IS_NOT_IDENTICAL;
|
|
219
|
+
} else {
|
|
220
|
+
this.input();
|
|
221
|
+
return this.tok.T_IS_NOT_EQUAL;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return "!";
|
|
225
|
+
},
|
|
226
|
+
"?"() {
|
|
227
|
+
if (this.version >= 700 && this._input[this.offset] === "?") {
|
|
228
|
+
if (this.version >= 704 && this._input[this.offset + 1] === "=") {
|
|
229
|
+
this.consume(2);
|
|
230
|
+
return this.tok.T_COALESCE_EQUAL;
|
|
231
|
+
} else {
|
|
232
|
+
this.input();
|
|
233
|
+
return this.tok.T_COALESCE;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (
|
|
237
|
+
this.version >= 800 &&
|
|
238
|
+
this._input[this.offset] === "-" &&
|
|
239
|
+
this._input[this.offset + 1] === ">"
|
|
240
|
+
) {
|
|
241
|
+
this.consume(1);
|
|
242
|
+
this.begin("ST_LOOKING_FOR_PROPERTY").input();
|
|
243
|
+
return this.tok.T_NULLSAFE_OBJECT_OPERATOR;
|
|
244
|
+
}
|
|
245
|
+
return "?";
|
|
246
|
+
},
|
|
247
|
+
"<"() {
|
|
248
|
+
let nchar = this._input[this.offset];
|
|
249
|
+
if (nchar === "<") {
|
|
250
|
+
nchar = this._input[this.offset + 1];
|
|
251
|
+
if (nchar === "=") {
|
|
252
|
+
this.consume(2);
|
|
253
|
+
return this.tok.T_SL_EQUAL;
|
|
254
|
+
} else if (nchar === "<") {
|
|
255
|
+
if (this.is_HEREDOC()) {
|
|
256
|
+
return this.tok.T_START_HEREDOC;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
this.input();
|
|
260
|
+
return this.tok.T_SL;
|
|
261
|
+
} else if (nchar === "=") {
|
|
262
|
+
this.input();
|
|
263
|
+
if (this.version >= 700 && this._input[this.offset] === ">") {
|
|
264
|
+
this.input();
|
|
265
|
+
return this.tok.T_SPACESHIP;
|
|
266
|
+
} else {
|
|
267
|
+
return this.tok.T_IS_SMALLER_OR_EQUAL;
|
|
268
|
+
}
|
|
269
|
+
} else if (nchar === ">") {
|
|
270
|
+
this.input();
|
|
271
|
+
return this.tok.T_IS_NOT_EQUAL;
|
|
272
|
+
}
|
|
273
|
+
return "<";
|
|
274
|
+
},
|
|
275
|
+
">"() {
|
|
276
|
+
let nchar = this._input[this.offset];
|
|
277
|
+
if (nchar === "=") {
|
|
278
|
+
this.input();
|
|
279
|
+
return this.tok.T_IS_GREATER_OR_EQUAL;
|
|
280
|
+
} else if (nchar === ">") {
|
|
281
|
+
nchar = this._input[this.offset + 1];
|
|
282
|
+
if (nchar === "=") {
|
|
283
|
+
this.consume(2);
|
|
284
|
+
return this.tok.T_SR_EQUAL;
|
|
285
|
+
} else {
|
|
286
|
+
this.input();
|
|
287
|
+
return this.tok.T_SR;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return ">";
|
|
291
|
+
},
|
|
292
|
+
"*"() {
|
|
293
|
+
const nchar = this._input[this.offset];
|
|
294
|
+
if (nchar === "=") {
|
|
295
|
+
this.input();
|
|
296
|
+
return this.tok.T_MUL_EQUAL;
|
|
297
|
+
} else if (nchar === "*") {
|
|
298
|
+
this.input();
|
|
299
|
+
if (this._input[this.offset] === "=") {
|
|
300
|
+
this.input();
|
|
301
|
+
return this.tok.T_POW_EQUAL;
|
|
302
|
+
} else {
|
|
303
|
+
return this.tok.T_POW;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return "*";
|
|
307
|
+
},
|
|
308
|
+
"."() {
|
|
309
|
+
const nchar = this._input[this.offset];
|
|
310
|
+
if (nchar === "=") {
|
|
311
|
+
this.input();
|
|
312
|
+
return this.tok.T_CONCAT_EQUAL;
|
|
313
|
+
} else if (nchar === "." && this._input[this.offset + 1] === ".") {
|
|
314
|
+
this.consume(2);
|
|
315
|
+
return this.tok.T_ELLIPSIS;
|
|
316
|
+
}
|
|
317
|
+
return ".";
|
|
318
|
+
},
|
|
319
|
+
"%"() {
|
|
320
|
+
if (this._input[this.offset] === "=") {
|
|
321
|
+
this.input();
|
|
322
|
+
return this.tok.T_MOD_EQUAL;
|
|
323
|
+
}
|
|
324
|
+
return "%";
|
|
325
|
+
},
|
|
326
|
+
"&"() {
|
|
327
|
+
const nchar = this._input[this.offset];
|
|
328
|
+
if (nchar === "=") {
|
|
329
|
+
this.input();
|
|
330
|
+
return this.tok.T_AND_EQUAL;
|
|
331
|
+
} else if (nchar === "&") {
|
|
332
|
+
this.input();
|
|
333
|
+
return this.tok.T_BOOLEAN_AND;
|
|
334
|
+
}
|
|
335
|
+
return "&";
|
|
336
|
+
},
|
|
337
|
+
"|"() {
|
|
338
|
+
const nchar = this._input[this.offset];
|
|
339
|
+
if (nchar === "=") {
|
|
340
|
+
this.input();
|
|
341
|
+
return this.tok.T_OR_EQUAL;
|
|
342
|
+
} else if (nchar === "|") {
|
|
343
|
+
this.input();
|
|
344
|
+
return this.tok.T_BOOLEAN_OR;
|
|
345
|
+
}
|
|
346
|
+
return "|";
|
|
347
|
+
},
|
|
348
|
+
"^"() {
|
|
349
|
+
if (this._input[this.offset] === "=") {
|
|
350
|
+
this.input();
|
|
351
|
+
return this.tok.T_XOR_EQUAL;
|
|
352
|
+
}
|
|
353
|
+
return "^";
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2018 Glayzzle (BSD3 License)
|
|
3
|
+
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
|
|
4
|
+
* @url http://glayzzle.com
|
|
5
|
+
*/
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const tokens = ";:,.\\[]()|^&+-/*=%!~$<>?@";
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
// check if the char can be a numeric
|
|
12
|
+
is_NUM() {
|
|
13
|
+
const ch = this._input.charCodeAt(this.offset - 1);
|
|
14
|
+
return (ch > 47 && ch < 58) || ch === 95;
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
// check if the char can be a numeric
|
|
18
|
+
is_NUM_START() {
|
|
19
|
+
const ch = this._input.charCodeAt(this.offset - 1);
|
|
20
|
+
return ch > 47 && ch < 58;
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
// check if current char can be a label
|
|
24
|
+
is_LABEL() {
|
|
25
|
+
const ch = this._input.charCodeAt(this.offset - 1);
|
|
26
|
+
return (
|
|
27
|
+
(ch > 96 && ch < 123) ||
|
|
28
|
+
(ch > 64 && ch < 91) ||
|
|
29
|
+
ch === 95 ||
|
|
30
|
+
(ch > 47 && ch < 58) ||
|
|
31
|
+
ch > 126
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
// check if current char can be a label
|
|
36
|
+
is_LABEL_START() {
|
|
37
|
+
const ch = this._input.charCodeAt(this.offset - 1);
|
|
38
|
+
// A - Z
|
|
39
|
+
if (ch > 64 && ch < 91) return true;
|
|
40
|
+
// a - z
|
|
41
|
+
if (ch > 96 && ch < 123) return true;
|
|
42
|
+
// _ (95)
|
|
43
|
+
if (ch === 95) return true;
|
|
44
|
+
// utf8 / extended
|
|
45
|
+
if (ch > 126) return true;
|
|
46
|
+
// else
|
|
47
|
+
return false;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
// reads each char of the label
|
|
51
|
+
consume_LABEL() {
|
|
52
|
+
while (this.offset < this.size) {
|
|
53
|
+
const ch = this.input();
|
|
54
|
+
if (!this.is_LABEL()) {
|
|
55
|
+
if (ch) this.unput(1);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return this;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
// check if current char is a token char
|
|
63
|
+
is_TOKEN() {
|
|
64
|
+
const ch = this._input[this.offset - 1];
|
|
65
|
+
return tokens.indexOf(ch) !== -1;
|
|
66
|
+
},
|
|
67
|
+
// check if current char is a whitespace
|
|
68
|
+
is_WHITESPACE() {
|
|
69
|
+
const ch = this._input[this.offset - 1];
|
|
70
|
+
return ch === " " || ch === "\t" || ch === "\n" || ch === "\r";
|
|
71
|
+
},
|
|
72
|
+
// check if current char is a whitespace (without newlines)
|
|
73
|
+
is_TABSPACE() {
|
|
74
|
+
const ch = this._input[this.offset - 1];
|
|
75
|
+
return ch === " " || ch === "\t";
|
|
76
|
+
},
|
|
77
|
+
// consume all whitespaces (excluding newlines)
|
|
78
|
+
consume_TABSPACE() {
|
|
79
|
+
while (this.offset < this.size) {
|
|
80
|
+
const ch = this.input();
|
|
81
|
+
if (!this.is_TABSPACE()) {
|
|
82
|
+
if (ch) this.unput(1);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return this;
|
|
87
|
+
},
|
|
88
|
+
// check if current char can be a hexadecimal number
|
|
89
|
+
is_HEX() {
|
|
90
|
+
const ch = this._input.charCodeAt(this.offset - 1);
|
|
91
|
+
// 0 - 9
|
|
92
|
+
if (ch > 47 && ch < 58) return true;
|
|
93
|
+
// A - F
|
|
94
|
+
if (ch > 64 && ch < 71) return true;
|
|
95
|
+
// a - f
|
|
96
|
+
if (ch > 96 && ch < 103) return true;
|
|
97
|
+
// _ (code 95)
|
|
98
|
+
if (ch === 95) return true;
|
|
99
|
+
// else
|
|
100
|
+
return false;
|
|
101
|
+
},
|
|
102
|
+
// check if current char can be an octal number
|
|
103
|
+
is_OCTAL() {
|
|
104
|
+
const ch = this._input.charCodeAt(this.offset - 1);
|
|
105
|
+
// 0 - 7
|
|
106
|
+
if (ch > 47 && ch < 56) return true;
|
|
107
|
+
// _ (code 95)
|
|
108
|
+
if (ch === 95) return true;
|
|
109
|
+
// else
|
|
110
|
+
return false;
|
|
111
|
+
},
|
|
112
|
+
};
|