Skip to content

Commit 3112d3d

Browse files
committed
1 parent fdc3988 commit 3112d3d

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

src/parser/function.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ module.exports = {
108108
break;
109109
} else {
110110
this.error([',', ')']);
111+
break;
111112
}
112113
}
113114
}

src/parser/namespace.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ module.exports = {
2020
this.currentNamespace = [''];
2121
return result([''], this.read_code_block(true));
2222
} else {
23-
if(this.token === this.tok.T_NAMESPACE) this.error(['{', this.tok.T_STRING]);
23+
if(this.token === this.tok.T_NAMESPACE) {
24+
this.error(['{', this.tok.T_STRING]);
25+
this.next(); // ignore namespace token
26+
}
2427
var name = this.read_namespace_name();
2528
if (this.token == ';') {
2629
this.currentNamespace = name;
@@ -38,6 +41,11 @@ module.exports = {
3841
);
3942
} else {
4043
this.error(['{', ';']);
44+
// graceful mode :
45+
this.currentNamespace = name;
46+
var body = this.read_top_statements();
47+
this.expect(this.EOF);
48+
return result(name, body);
4149
}
4250
}
4351
}

src/parser/scalar.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ module.exports = {
109109
case '[': // short array format
110110
return this.read_array();
111111
default:
112-
this.error('SCALAR');
112+
var err = this.error('SCALAR');
113+
// graceful mode : ignore token & return error node
114+
this.next();
115+
return err;
113116
}
114117
}
115118
}

src/parser/statement.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ module.exports = {
147147
case this.tok.T_INTERFACE:
148148
return this.read_interface(flag);
149149
default:
150-
this.error([this.tok.T_CLASS, this.tok.T_INTERFACE]);
150+
var err = this.error([this.tok.T_CLASS, this.tok.T_INTERFACE]);
151+
// graceful mode : ignore token & go next
152+
this.next();
153+
return err;
151154
}
152155
case this.tok.T_CLASS:
153156
return this.read_class(0);

src/parser/variable.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ module.exports = {
5959
getter = this.text();
6060
this.next();
6161
} else {
62-
this.error([this.tok.T_VARIABLE, this.tok.T_STRING]);
62+
getter = this.error([this.tok.T_VARIABLE, this.tok.T_STRING]);
63+
// graceful mode : set getter as error node and continue
64+
this.next();
6365
}
6466
if (from[0] != 'ns') {
6567
from = ['lookup', 'class', from];
@@ -131,7 +133,10 @@ module.exports = {
131133
this.expect('}').next();
132134
break;
133135
default:
134-
this.error([this.tok.T_STRING, this.tok.T_VARIABLE]);
136+
what = this.error([this.tok.T_STRING, this.tok.T_VARIABLE]);
137+
// graceful mode : set what as error mode & continue
138+
this.next();
139+
break;
135140
}
136141
result = ['prop', result, what];
137142
break;
@@ -217,7 +222,9 @@ module.exports = {
217222
this.next();
218223
break;
219224
default:
220-
this.error(['{', '$', this.tok.T_VARIABLE]);
225+
result = this.error(['{', '$', this.tok.T_VARIABLE]);
226+
// graceful mode
227+
this.next();
221228
}
222229
result = ['lookup', 'var', result];
223230
}

0 commit comments

Comments
 (0)