-
Notifications
You must be signed in to change notification settings - Fork 0
/
value.dart
54 lines (44 loc) · 1.2 KB
/
value.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
47
48
49
50
51
52
53
54
part of '../../combinator.dart';
class Value<I, O> extends ParserBuilder<I, O> {
static const _template = '''
state.ok = true;
if (state.ok) {
{{res0}} = {{value}};
}''';
static const _templateFast = '''
state.ok = true;''';
static const _templateParser = '''
{{p1}}
if (state.ok) {
{{res0}} = {{value}};
}''';
static const _templateParserFast = '''
{{p1}}''';
final ParserBuilder<I, dynamic>? parser;
final O value;
const Value(this.value, [this.parser]);
@override
String build(Context context, ParserResult? result) {
if (parser != null) {
return _buildWithParser(context, result);
} else {
return _build(context, result);
}
}
String _build(Context context, ParserResult? result) {
final fast = result == null;
final values = {
'value': helper.getAsCode(value),
};
return render2(fast, _templateFast, _template, values, [result]);
}
String _buildWithParser(Context context, ParserResult? result) {
final fast = result == null;
final values = {
'p1': parser!.build(context, null),
'value': helper.getAsCode(value),
};
return render2(
fast, _templateParserFast, _templateParser, values, [result]);
}
}