File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
test/code/parser/errorHandling Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -132,9 +132,21 @@ public function getErrors() {
132
132
* unable to recover from an error).
133
133
*/
134
134
public function parse ($ code ) {
135
- $ this ->lexer ->startLexing ($ code );
136
135
$ this ->errors = array ();
137
136
137
+ // Initialize the lexer
138
+ try {
139
+ $ this ->lexer ->startLexing ($ code );
140
+ } catch (Error $ e ) {
141
+ $ this ->errors [] = $ e ;
142
+ if ($ this ->throwOnError ) {
143
+ throw $ e ;
144
+ } else {
145
+ // Currently can't recover from lexer errors
146
+ return null ;
147
+ }
148
+ }
149
+
138
150
// We start off with no lookahead-token
139
151
$ symbol = self ::SYMBOL_NONE ;
140
152
Original file line number Diff line number Diff line change
1
+ Lexer errors
2
+ -----
3
+ <?php
4
+
5
+ $a = 42;
6
+ /*
7
+ $b = 24;
8
+ -----
9
+ Unterminated comment on line 4
10
+ -----
11
+ <?php
12
+
13
+ $a = 42;
14
+ @@{ "\1" }@@
15
+ $b = 24;
16
+ -----
17
+ Unexpected character "@@{ "\1" }@@" (ASCII 1) on unknown line
18
+ -----
19
+ <?php
20
+
21
+ $a = 42;
22
+ @@{ "\0" }@@
23
+ $b = 24;
24
+ -----
25
+ Unexpected null byte on unknown line
You can’t perform that action at this time.
0 commit comments