@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,168 @@
|
|
|
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
|
+
/*
|
|
10
|
+
* Reads a while statement
|
|
11
|
+
* ```ebnf
|
|
12
|
+
* while ::= T_WHILE (statement | ':' inner_statement_list T_ENDWHILE ';')
|
|
13
|
+
* ```
|
|
14
|
+
* @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L587
|
|
15
|
+
* @return {While}
|
|
16
|
+
*/
|
|
17
|
+
read_while() {
|
|
18
|
+
const result = this.node("while");
|
|
19
|
+
this.expect(this.tok.T_WHILE) && this.next();
|
|
20
|
+
let test = null;
|
|
21
|
+
let body = null;
|
|
22
|
+
let shortForm = false;
|
|
23
|
+
if (this.expect("(")) this.next();
|
|
24
|
+
test = this.read_expr();
|
|
25
|
+
if (this.expect(")")) this.next();
|
|
26
|
+
if (this.token === ":") {
|
|
27
|
+
shortForm = true;
|
|
28
|
+
body = this.read_short_form(this.tok.T_ENDWHILE);
|
|
29
|
+
} else {
|
|
30
|
+
body = this.read_statement();
|
|
31
|
+
}
|
|
32
|
+
return result(test, body, shortForm);
|
|
33
|
+
},
|
|
34
|
+
/*
|
|
35
|
+
* Reads a do / while loop
|
|
36
|
+
* ```ebnf
|
|
37
|
+
* do ::= T_DO statement T_WHILE '(' expr ')' ';'
|
|
38
|
+
* ```
|
|
39
|
+
* @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L423
|
|
40
|
+
* @return {Do}
|
|
41
|
+
*/
|
|
42
|
+
read_do() {
|
|
43
|
+
const result = this.node("do");
|
|
44
|
+
this.expect(this.tok.T_DO) && this.next();
|
|
45
|
+
let test = null;
|
|
46
|
+
let body = null;
|
|
47
|
+
body = this.read_statement();
|
|
48
|
+
if (this.expect(this.tok.T_WHILE)) {
|
|
49
|
+
if (this.next().expect("(")) this.next();
|
|
50
|
+
test = this.read_expr();
|
|
51
|
+
if (this.expect(")")) this.next();
|
|
52
|
+
if (this.expect(";")) this.next();
|
|
53
|
+
}
|
|
54
|
+
return result(test, body);
|
|
55
|
+
},
|
|
56
|
+
/*
|
|
57
|
+
* Read a for incremental loop
|
|
58
|
+
* ```ebnf
|
|
59
|
+
* for ::= T_FOR '(' for_exprs ';' for_exprs ';' for_exprs ')' for_statement
|
|
60
|
+
* for_statement ::= statement | ':' inner_statement_list T_ENDFOR ';'
|
|
61
|
+
* for_exprs ::= expr? (',' expr)*
|
|
62
|
+
* ```
|
|
63
|
+
* @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L425
|
|
64
|
+
* @return {For}
|
|
65
|
+
*/
|
|
66
|
+
read_for() {
|
|
67
|
+
const result = this.node("for");
|
|
68
|
+
this.expect(this.tok.T_FOR) && this.next();
|
|
69
|
+
let init = [];
|
|
70
|
+
let test = [];
|
|
71
|
+
let increment = [];
|
|
72
|
+
let body = null;
|
|
73
|
+
let shortForm = false;
|
|
74
|
+
if (this.expect("(")) this.next();
|
|
75
|
+
if (this.token !== ";") {
|
|
76
|
+
init = this.read_list(this.read_expr, ",");
|
|
77
|
+
if (this.expect(";")) this.next();
|
|
78
|
+
} else {
|
|
79
|
+
this.next();
|
|
80
|
+
}
|
|
81
|
+
if (this.token !== ";") {
|
|
82
|
+
test = this.read_list(this.read_expr, ",");
|
|
83
|
+
if (this.expect(";")) this.next();
|
|
84
|
+
} else {
|
|
85
|
+
this.next();
|
|
86
|
+
}
|
|
87
|
+
if (this.token !== ")") {
|
|
88
|
+
increment = this.read_list(this.read_expr, ",");
|
|
89
|
+
if (this.expect(")")) this.next();
|
|
90
|
+
} else {
|
|
91
|
+
this.next();
|
|
92
|
+
}
|
|
93
|
+
if (this.token === ":") {
|
|
94
|
+
shortForm = true;
|
|
95
|
+
body = this.read_short_form(this.tok.T_ENDFOR);
|
|
96
|
+
} else {
|
|
97
|
+
body = this.read_statement();
|
|
98
|
+
}
|
|
99
|
+
return result(init, test, increment, body, shortForm);
|
|
100
|
+
},
|
|
101
|
+
/*
|
|
102
|
+
* Reads a foreach loop
|
|
103
|
+
* ```ebnf
|
|
104
|
+
* foreach ::= '(' expr T_AS foreach_variable (T_DOUBLE_ARROW foreach_variable)? ')' statement
|
|
105
|
+
* ```
|
|
106
|
+
* @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L438
|
|
107
|
+
* @return {Foreach}
|
|
108
|
+
*/
|
|
109
|
+
read_foreach() {
|
|
110
|
+
const result = this.node("foreach");
|
|
111
|
+
this.expect(this.tok.T_FOREACH) && this.next();
|
|
112
|
+
let source = null;
|
|
113
|
+
let key = null;
|
|
114
|
+
let value = null;
|
|
115
|
+
let body = null;
|
|
116
|
+
let shortForm = false;
|
|
117
|
+
if (this.expect("(")) this.next();
|
|
118
|
+
source = this.read_expr();
|
|
119
|
+
if (this.expect(this.tok.T_AS)) {
|
|
120
|
+
this.next();
|
|
121
|
+
value = this.read_foreach_variable();
|
|
122
|
+
if (this.token === this.tok.T_DOUBLE_ARROW) {
|
|
123
|
+
key = value;
|
|
124
|
+
value = this.next().read_foreach_variable();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// grammatically correct but not supported by PHP
|
|
129
|
+
if (key && key.kind === "list") {
|
|
130
|
+
this.raiseError("Fatal Error : Cannot use list as key element");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (this.expect(")")) this.next();
|
|
134
|
+
|
|
135
|
+
if (this.token === ":") {
|
|
136
|
+
shortForm = true;
|
|
137
|
+
body = this.read_short_form(this.tok.T_ENDFOREACH);
|
|
138
|
+
} else {
|
|
139
|
+
body = this.read_statement();
|
|
140
|
+
}
|
|
141
|
+
return result(source, key, value, body, shortForm);
|
|
142
|
+
},
|
|
143
|
+
/*
|
|
144
|
+
* Reads a foreach variable statement
|
|
145
|
+
* ```ebnf
|
|
146
|
+
* foreach_variable =
|
|
147
|
+
* variable |
|
|
148
|
+
* '&' variable |
|
|
149
|
+
* T_LIST '(' assignment_list ')' |
|
|
150
|
+
* '[' assignment_list ']'
|
|
151
|
+
* ```
|
|
152
|
+
* @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L544
|
|
153
|
+
* @return {Expression}
|
|
154
|
+
*/
|
|
155
|
+
read_foreach_variable() {
|
|
156
|
+
if (this.token === this.tok.T_LIST || this.token === "[") {
|
|
157
|
+
const isShort = this.token === "[";
|
|
158
|
+
const result = this.node("list");
|
|
159
|
+
this.next();
|
|
160
|
+
if (!isShort && this.expect("(")) this.next();
|
|
161
|
+
const assignList = this.read_array_pair_list(isShort);
|
|
162
|
+
if (this.expect(isShort ? "]" : ")")) this.next();
|
|
163
|
+
return result(assignList, isShort);
|
|
164
|
+
} else {
|
|
165
|
+
return this.read_variable(false, false);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
/*
|
|
10
|
+
* ```ebnf
|
|
11
|
+
* start ::= (namespace | top_statement)*
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
read_start() {
|
|
15
|
+
if (this.token == this.tok.T_NAMESPACE) {
|
|
16
|
+
return this.read_namespace();
|
|
17
|
+
} else {
|
|
18
|
+
return this.read_top_statement();
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
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
|
+
/*
|
|
10
|
+
* Reads a namespace declaration block
|
|
11
|
+
* ```ebnf
|
|
12
|
+
* namespace ::= T_NAMESPACE namespace_name? '{'
|
|
13
|
+
* top_statements
|
|
14
|
+
* '}'
|
|
15
|
+
* | T_NAMESPACE namespace_name ';' top_statements
|
|
16
|
+
* ```
|
|
17
|
+
* @see http://php.net/manual/en/language.namespaces.php
|
|
18
|
+
* @return {Namespace}
|
|
19
|
+
*/
|
|
20
|
+
read_namespace() {
|
|
21
|
+
const result = this.node("namespace");
|
|
22
|
+
let body;
|
|
23
|
+
this.expect(this.tok.T_NAMESPACE) && this.next();
|
|
24
|
+
let name;
|
|
25
|
+
|
|
26
|
+
if (this.token === "{") {
|
|
27
|
+
name = {
|
|
28
|
+
name: [""],
|
|
29
|
+
};
|
|
30
|
+
} else {
|
|
31
|
+
name = this.read_namespace_name();
|
|
32
|
+
}
|
|
33
|
+
this.currentNamespace = name;
|
|
34
|
+
|
|
35
|
+
if (this.token === ";") {
|
|
36
|
+
this.currentNamespace = name;
|
|
37
|
+
body = this.next().read_top_statements();
|
|
38
|
+
this.expect(this.EOF);
|
|
39
|
+
return result(name.name, body, false);
|
|
40
|
+
} else if (this.token === "{") {
|
|
41
|
+
this.currentNamespace = name;
|
|
42
|
+
body = this.next().read_top_statements();
|
|
43
|
+
this.expect("}") && this.next();
|
|
44
|
+
if (
|
|
45
|
+
body.length === 0 &&
|
|
46
|
+
this.extractDoc &&
|
|
47
|
+
this._docs.length > this._docIndex
|
|
48
|
+
) {
|
|
49
|
+
body.push(this.node("noop")());
|
|
50
|
+
}
|
|
51
|
+
return result(name.name, body, true);
|
|
52
|
+
} else {
|
|
53
|
+
this.error(["{", ";"]);
|
|
54
|
+
// graceful mode :
|
|
55
|
+
this.currentNamespace = name;
|
|
56
|
+
body = this.read_top_statements();
|
|
57
|
+
this.expect(this.EOF);
|
|
58
|
+
return result(name, body, false);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
/*
|
|
62
|
+
* Reads a namespace name
|
|
63
|
+
* ```ebnf
|
|
64
|
+
* namespace_name ::= T_NS_SEPARATOR? (T_STRING T_NS_SEPARATOR)* T_STRING
|
|
65
|
+
* ```
|
|
66
|
+
* @see http://php.net/manual/en/language.namespaces.rules.php
|
|
67
|
+
* @return {Reference}
|
|
68
|
+
*/
|
|
69
|
+
read_namespace_name(resolveReference) {
|
|
70
|
+
const result = this.node();
|
|
71
|
+
let resolution;
|
|
72
|
+
let name = this.text();
|
|
73
|
+
switch (this.token) {
|
|
74
|
+
case this.tok.T_NAME_RELATIVE:
|
|
75
|
+
resolution = this.ast.name.RELATIVE_NAME;
|
|
76
|
+
name = name.replace(/^namespace\\/, "");
|
|
77
|
+
break;
|
|
78
|
+
case this.tok.T_NAME_QUALIFIED:
|
|
79
|
+
resolution = this.ast.name.QUALIFIED_NAME;
|
|
80
|
+
break;
|
|
81
|
+
case this.tok.T_NAME_FULLY_QUALIFIED:
|
|
82
|
+
resolution = this.ast.name.FULL_QUALIFIED_NAME;
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
resolution = this.ast.name.UNQUALIFIED_NAME;
|
|
86
|
+
if (!this.expect(this.tok.T_STRING)) {
|
|
87
|
+
// graceful mode
|
|
88
|
+
return result("name", "", this.ast.name.FULL_QUALIFIED_NAME);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
this.next();
|
|
93
|
+
|
|
94
|
+
if (resolveReference || this.token !== "(") {
|
|
95
|
+
if (name.toLowerCase() === "parent") {
|
|
96
|
+
return result("parentreference", name);
|
|
97
|
+
} else if (name.toLowerCase() === "self") {
|
|
98
|
+
return result("selfreference", name);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return result("name", name, resolution);
|
|
103
|
+
},
|
|
104
|
+
/*
|
|
105
|
+
* Reads a use statement
|
|
106
|
+
* ```ebnf
|
|
107
|
+
* use_statement ::= T_USE
|
|
108
|
+
* use_type? use_declarations |
|
|
109
|
+
* use_type use_statement '{' use_declarations '}' |
|
|
110
|
+
* use_statement '{' use_declarations(=>typed) '}'
|
|
111
|
+
* ';'
|
|
112
|
+
* ```
|
|
113
|
+
* @see http://php.net/manual/en/language.namespaces.importing.php
|
|
114
|
+
* @return {UseGroup}
|
|
115
|
+
*/
|
|
116
|
+
read_use_statement() {
|
|
117
|
+
let result = this.node("usegroup");
|
|
118
|
+
let items = [];
|
|
119
|
+
let name = null;
|
|
120
|
+
this.expect(this.tok.T_USE) && this.next();
|
|
121
|
+
const type = this.read_use_type();
|
|
122
|
+
items.push(this.read_use_declaration(false));
|
|
123
|
+
if (this.token === ",") {
|
|
124
|
+
items = items.concat(this.next().read_use_declarations(false));
|
|
125
|
+
} else if (this.token === "{") {
|
|
126
|
+
name = items[0].name;
|
|
127
|
+
items = this.next().read_use_declarations(type === null);
|
|
128
|
+
this.expect("}") && this.next();
|
|
129
|
+
}
|
|
130
|
+
result = result(name, type, items);
|
|
131
|
+
this.expect(";") && this.next();
|
|
132
|
+
return result;
|
|
133
|
+
},
|
|
134
|
+
/*
|
|
135
|
+
*
|
|
136
|
+
* @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1045
|
|
137
|
+
*/
|
|
138
|
+
read_class_name_reference() {
|
|
139
|
+
// resolved as the same
|
|
140
|
+
return this.read_variable(true, false);
|
|
141
|
+
},
|
|
142
|
+
/*
|
|
143
|
+
* Reads a use declaration
|
|
144
|
+
* ```ebnf
|
|
145
|
+
* use_declaration ::= use_type? namespace_name use_alias
|
|
146
|
+
* ```
|
|
147
|
+
* @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L380
|
|
148
|
+
* @return {UseItem}
|
|
149
|
+
*/
|
|
150
|
+
read_use_declaration(typed) {
|
|
151
|
+
const result = this.node("useitem");
|
|
152
|
+
let type = null;
|
|
153
|
+
if (typed) type = this.read_use_type();
|
|
154
|
+
const name = this.read_namespace_name();
|
|
155
|
+
const alias = this.read_use_alias();
|
|
156
|
+
return result(name.name, alias, type);
|
|
157
|
+
},
|
|
158
|
+
/*
|
|
159
|
+
* Reads a list of use declarations
|
|
160
|
+
* ```ebnf
|
|
161
|
+
* use_declarations ::= use_declaration (',' use_declaration)*
|
|
162
|
+
* ```
|
|
163
|
+
* @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L380
|
|
164
|
+
* @return {UseItem[]}
|
|
165
|
+
*/
|
|
166
|
+
read_use_declarations(typed) {
|
|
167
|
+
const result = [this.read_use_declaration(typed)];
|
|
168
|
+
while (this.token === ",") {
|
|
169
|
+
this.next();
|
|
170
|
+
if (typed) {
|
|
171
|
+
if (
|
|
172
|
+
this.token !== this.tok.T_NAME_RELATIVE &&
|
|
173
|
+
this.token !== this.tok.T_NAME_QUALIFIED &&
|
|
174
|
+
this.token !== this.tok.T_NAME_FULLY_QUALIFIED &&
|
|
175
|
+
this.token !== this.tok.T_FUNCTION &&
|
|
176
|
+
this.token !== this.tok.T_CONST &&
|
|
177
|
+
this.token !== this.tok.T_STRING
|
|
178
|
+
) {
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
} else if (
|
|
182
|
+
this.token !== this.tok.T_NAME_RELATIVE &&
|
|
183
|
+
this.token !== this.tok.T_NAME_QUALIFIED &&
|
|
184
|
+
this.token !== this.tok.T_NAME_FULLY_QUALIFIED &&
|
|
185
|
+
this.token !== this.tok.T_STRING &&
|
|
186
|
+
this.token !== this.tok.T_NS_SEPARATOR
|
|
187
|
+
) {
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
result.push(this.read_use_declaration(typed));
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
},
|
|
194
|
+
/*
|
|
195
|
+
* Reads a use statement
|
|
196
|
+
* ```ebnf
|
|
197
|
+
* use_alias ::= (T_AS T_STRING)?
|
|
198
|
+
* ```
|
|
199
|
+
* @return {String|null}
|
|
200
|
+
*/
|
|
201
|
+
read_use_alias() {
|
|
202
|
+
let result = null;
|
|
203
|
+
if (this.token === this.tok.T_AS) {
|
|
204
|
+
if (this.next().expect(this.tok.T_STRING)) {
|
|
205
|
+
const aliasName = this.node("identifier");
|
|
206
|
+
const name = this.text();
|
|
207
|
+
this.next();
|
|
208
|
+
result = aliasName(name);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
},
|
|
213
|
+
/*
|
|
214
|
+
* Reads the namespace type declaration
|
|
215
|
+
* ```ebnf
|
|
216
|
+
* use_type ::= (T_FUNCTION | T_CONST)?
|
|
217
|
+
* ```
|
|
218
|
+
* @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L335
|
|
219
|
+
* @return {String|null} Possible values : function, const
|
|
220
|
+
*/
|
|
221
|
+
read_use_type() {
|
|
222
|
+
if (this.token === this.tok.T_FUNCTION) {
|
|
223
|
+
this.next();
|
|
224
|
+
return this.ast.useitem.TYPE_FUNCTION;
|
|
225
|
+
} else if (this.token === this.tok.T_CONST) {
|
|
226
|
+
this.next();
|
|
227
|
+
return this.ast.useitem.TYPE_CONST;
|
|
228
|
+
}
|
|
229
|
+
return null;
|
|
230
|
+
},
|
|
231
|
+
};
|