-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskip_while.dart
46 lines (41 loc) · 1.03 KB
/
skip_while.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
part of '../../bytes.dart';
/// Parses while [predicate] satisfies the criteria, and returns true.
///
/// Example:
/// ```dart
/// SkipWhile(CharClass('#x9 | #xA | #xD | #x20'))
/// ```
class SkipWhile extends ParserBuilder<String, void> {
static const _template16 = '''
while (state.pos < source.length) {
final c = source.codeUnitAt(state.pos);
final ok = {{test}};
if (!ok) {
break;
}
state.pos++;
}
state.ok = true;''';
static const _template32 = '''
while (state.pos < source.length) {
final pos = state.pos;
final c = source.readRune(state);
final ok = {{test}};
if (!ok) {
state.pos = pos;
break;
}
}
state.ok = true;''';
final SemanticAction<bool> predicate;
const SkipWhile(this.predicate);
@override
String build(Context context, ParserResult? result) {
context.refersToStateSource = true;
final isUnicode = predicate.isUnicode;
final values = {
'test': predicate.build(context, 'test', ['c']),
};
return render2(isUnicode, _template32, _template16, values);
}
}