-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag_of.dart
45 lines (40 loc) · 1019 Bytes
/
tag_of.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
part of '../../bytes.dart';
class TagOf extends ParserBuilder<String, String> {
static const _template = '''
{{var1}}
{{p1}}
if (state.ok) {
final tag = {{val1}};
state.ok = source.startsWith(tag, state.pos);
if (state.ok) {
state.pos += tag.length;
{{res0}} = tag;
} else {
state.fail(state.pos, ParseError.expected, tag);
}
}''';
static const _templateFast = '''
{{var1}}
{{p1}}
if (state.ok) {
final tag = {{val1}};
state.ok = source.startsWith(tag, state.pos);
if (state.ok) {
state.pos += tag.length;
} else {
state.fail(state.pos, ParseError.expected, tag);
}
}''';
final ParserBuilder<String, String> tag;
const TagOf(this.tag);
@override
String build(Context context, ParserResult? result) {
context.refersToStateSource = true;
final fast = result == null;
final r1 = context.getResult(tag, true);
final values = {
'p1': tag.build(context, r1),
};
return render2(fast, _templateFast, _template, values, [result, r1]);
}
}