Skip to content

Commit 6f778bb

Browse files
committed
add scalar tests & remove unused path
1 parent 7526ea2 commit 6f778bb

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

src/parser.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ var parser = function(lexer, ast) {
3333
this.extractDoc = false;
3434
this.suppressErrors = false;
3535
this.entries = {
36+
'VARIABLE': [
37+
this.tok.T_VARIABLE,
38+
'$', '&',
39+
this.tok.T_NS_SEPARATOR,
40+
this.tok.T_STRING,
41+
this.tok.T_NAMESPACE,
42+
this.tok.T_STATIC
43+
],
3644
'SCALAR': [
3745
this.tok.T_CONSTANT_ENCAPSED_STRING,
3846
this.tok.T_START_HEREDOC,
3947
this.tok.T_LNUMBER,
4048
this.tok.T_DNUMBER,
41-
this.tok.T_STRING,
4249
this.tok.T_ARRAY,'[',
4350
this.tok.T_CLASS_C,
4451
this.tok.T_TRAIT_C,
@@ -48,7 +55,6 @@ var parser = function(lexer, ast) {
4855
this.tok.T_FILE,
4956
this.tok.T_DIR,
5057
this.tok.T_NS_C,
51-
this.tok.T_NAMESPACE,
5258
'"',
5359
'b"',
5460
'B"',
@@ -73,13 +79,6 @@ var parser = function(lexer, ast) {
7379
this.tok.T_ABSTRACT,
7480
this.tok.T_FINAL
7581
],
76-
'VARIABLE': [
77-
this.tok.T_VARIABLE,
78-
'$', '&',
79-
this.tok.T_NS_SEPARATOR,
80-
this.tok.T_STRING,
81-
this.tok.T_STATIC
82-
],
8382
'EOS': [
8483
';',
8584
this.tok.T_CLOSE_TAG,

src/parser/scalar.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -111,28 +111,6 @@ module.exports = {
111111
result = result(value);
112112
return result;
113113

114-
// CONSTANTS
115-
case this.tok.T_NAMESPACE:
116-
case this.tok.T_NS_SEPARATOR:
117-
case this.tok.T_STRING:
118-
var value = this.read_namespace_name();
119-
var result = ['constant', value];
120-
if ( this.token == this.tok.T_DOUBLE_COLON) {
121-
// class constant MyClass::CONSTANT
122-
if (this.next().expect([this.tok.T_STRING, this.tok.T_CLASS])) {
123-
result[1] = [value, this.text()];
124-
this.next();
125-
}
126-
}
127-
// CONSTANT ARRAYS OFFSET : MYCONST[1][0]...
128-
while(this.token === '[') {
129-
var node = this.node('offsetlookup');
130-
var offset = this.next().read_expr();
131-
if (this.expect(']')) this.next();
132-
result = node(result, offset);
133-
}
134-
return result;
135-
136114
// ARRAYS
137115
case this.tok.T_ARRAY: // array parser
138116
case '[': // short array format
@@ -217,18 +195,18 @@ module.exports = {
217195
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1246
218196
else if (this.token === this.tok.T_CURLY_OPEN) {
219197
result = this.next().read_variable(false, false, false);
220-
if (this.expect('}')) this.next();
198+
this.expect('}') && this.next();
221199
}
222200

223201
// plain variable
224202
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1231
225203
else if (this.token === this.tok.T_VARIABLE) {
226-
result = this.read_variable(false, true, false);
204+
result = this.read_simple_variable(false);
227205

228206
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1233
229207
if (this.token === '[') {
230208
var node = this.node('offsetlookup');
231-
var offset = this.next().read_expr();
209+
var offset = this.next().read_encaps_var_offset();
232210
this.expect(']') && this.next();
233211
result = node(result, offset);
234212
}

src/parser/variable.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = {
3333
// reads the entry point
3434
if (this.is([this.tok.T_VARIABLE, '$'])) {
3535
result = this.read_reference_variable(encapsed, byref);
36-
} else if (this.is([this.tok.T_NS_SEPARATOR, this.tok.T_STRING])) {
36+
} else if (this.is([this.tok.T_NS_SEPARATOR, this.tok.T_STRING, this.tok.T_NAMESPACE])) {
3737
result = this.node();
3838
var name = this.read_namespace_name();
3939
if (
@@ -235,13 +235,14 @@ module.exports = {
235235
while(this.token != this.EOF) {
236236
var node = this.node();
237237
if (this.token == '[') {
238+
var offset = null;
238239
if (encapsed) {
239-
result = this.next().read_encaps_var_offset();
240+
offset = this.next().read_encaps_var_offset();
240241
} else {
241-
var offset = this.next().token === ']' ? null : this.read_dim_offset();
242-
result = node('offsetlookup', result, offset);
242+
offset = this.next().token === ']' ? null : this.read_dim_offset();
243243
}
244244
this.expect(']') && this.next();
245+
result = node('offsetlookup', result, offset);
245246
} else if (this.token == '{' && !encapsed) {
246247
var offset = this.next().read_expr();
247248
this.expect('}') && this.next();

test/scalarTests.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var should = require("should");
2+
var parser = require('./main');
3+
4+
describe('Test scalar statements', function() {
5+
it('constants', function() {
6+
var ast = parser.parseEval([
7+
'$a = foo::ref[-5];'
8+
].join('\n'), {
9+
parser: {
10+
debug: true
11+
}
12+
});
13+
console.log(ast);
14+
});
15+
});

0 commit comments

Comments
 (0)