Skip to content

Commit 96b9420

Browse files
committed
glayzzle#95 checking identifier at the end
1 parent 5864372 commit 96b9420

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

src/parser/class.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,12 @@ module.exports = {
412412
if (this.token === this.tok.T_DOUBLE_COLON) {
413413
this.next();
414414

415-
if (this.is('IDENTIFIER') || this.expect(this.tok.T_STRING)) {
415+
if (this.token === this.tok.T_STRING || this.is('IDENTIFIER')) {
416416
trait = method;
417417
method = this.text();
418418
this.next();
419+
} else {
420+
this.expect(this.tok.T_STRING);
419421
}
420422
} else {
421423
// convert identifier as string
@@ -440,7 +442,7 @@ module.exports = {
440442
flags = this.read_member_flags();
441443
}
442444

443-
if (this.is('IDENTIFIER') || this.token === this.tok.T_STRING) {
445+
if (this.token === this.tok.T_STRING || this.is('IDENTIFIER')) {
444446
alias = this.text();
445447
this.next();
446448
} else if (flags === false) {

src/parser/function.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
*/
1111
is_reference: function() {
1212
if (this.token == '&') {
13-
this.next();
13+
this.next().ignoreComments();
1414
return true;
1515
}
1616
return false;
@@ -20,7 +20,7 @@ module.exports = {
2020
*/
2121
,is_variadic: function() {
2222
if (this.token === this.tok.T_ELLIPSIS) {
23-
this.next();
23+
this.next().ignoreComments();
2424
return true;
2525
}
2626
return false;
@@ -71,16 +71,23 @@ module.exports = {
7171
var result = this.node(nodeName);
7272

7373
if (this.expect(this.tok.T_FUNCTION)) {
74-
this.next();
74+
this.next().ignoreComments();
7575
}
7676
var isRef = this.is_reference();
7777
var name = false, use = [], returnType = null, nullable = false;
7878
if (type !== 1) {
79-
if ((type === 2 && this.is('IDENTIFIER')) || this.expect(this.tok.T_STRING)) {
80-
name = this.text();
81-
this.next();
79+
if (type === 2) {
80+
if (this.token === this.tok.T_STRING || this.is('IDENTIFIER')) {
81+
name = this.text();
82+
this.next();
83+
} else {
84+
this.error('IDENTIFIER');
85+
}
8286
} else {
83-
this.next();
87+
if (this.expect(this.tok.T_STRING)) {
88+
name = this.text();
89+
}
90+
this.next();
8491
}
8592
}
8693
if (this.expect('(')) this.next();

src/parser/variable.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ module.exports = {
7676
if (this.next().is([this.tok.T_VARIABLE, '$'])) {
7777
offset = this.read_reference_variable(encapsed, false);
7878
} else if (
79-
this.is('IDENTIFIER') || this.token === this.tok.T_STRING
80-
|| this.token === this.tok.T_CLASS
79+
this.token === this.tok.T_STRING
80+
|| this.token === this.tok.T_CLASS
81+
|| this.is('IDENTIFIER')
8182
) {
8283
offset = this.node('constref');
8384
var name = this.text();

test/commentTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('Test comments', function() {
6565
'/**',
6666
' * Description',
6767
' */',
68-
'function /* ignore */ name(/* */ $arg) {',
68+
'function /* ignore */ & /* ignore */ name(/* */ $arg) {',
6969
'// inner',
7070
'return $arg /* ignore */;',
7171
'}'

0 commit comments

Comments
 (0)