@@ -123,8 +123,6 @@ Map<String, String> ESCAPE = {"n":"\n", "f":"\f", "r":"\r", "t":"\t", "v":"\v",
123
123
124
124
ParsedFn ZERO = new ParsedFn ((_, _x) => 0 );
125
125
126
- class BreakException {}
127
-
128
126
class Setter {
129
127
operator []= (name, value){}
130
128
}
@@ -267,16 +265,16 @@ class Parser {
267
265
268
266
String peek () => index + 1 < textLength ? text[index + 1 ] : "EOF" ;
269
267
270
- breakWhile () { throw new BreakException (); }
268
+ // whileChars takes two functions: One called for each character
269
+ // and a second, optional function call at the end of the file.
270
+ // If the first function returns false, the the loop stops and endFn
271
+ // is not run.
271
272
whileChars (fn (), [endFn ()]) {
272
273
while (index < textLength) {
273
274
ch = text[index];
274
275
int lastIndex = index;
275
- try {
276
- fn ();
277
- } on BreakException catch (e) {
278
- endFn = null ;
279
- break ;
276
+ if (fn () == false ) {
277
+ return ;
280
278
}
281
279
if (lastIndex >= index) {
282
280
throw "while chars loop must advance at index $index " ;
@@ -315,14 +313,14 @@ class Parser {
315
313
}
316
314
index++ ;
317
315
}
318
- breakWhile ();
316
+ return false ; // BREAK
319
317
});
320
318
} else if (ch == quote) {
321
319
index++ ;
322
320
tokens.add (new Token (start, rawString)
323
321
..withString (string)
324
322
..withFn0 (() => string));
325
- breakWhile ();
323
+ return false ; // BREAK
326
324
} else {
327
325
string += ch;
328
326
index++ ;
@@ -354,7 +352,7 @@ class Parser {
354
352
isIn (EXP_OP , number[number.length - 1 ])) {
355
353
throw "Lexer Error: Invalid exponent at column $index in expression [$text ]." ;
356
354
} else {
357
- breakWhile ();
355
+ return false ; // BREAK
358
356
}
359
357
}
360
358
index++ ;
@@ -377,7 +375,7 @@ class Parser {
377
375
}
378
376
ident += ch;
379
377
} else {
380
- breakWhile ();
378
+ return false ; // BREAK
381
379
}
382
380
index++ ;
383
381
});
0 commit comments