-
Notifications
You must be signed in to change notification settings - Fork 0
/
hex_color_parser_builder.dart
38 lines (33 loc) · 1.29 KB
/
hex_color_parser_builder.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
import 'package:parser_builder/bytes.dart';
import 'package:parser_builder/char_class.dart';
import 'package:parser_builder/combinator.dart';
import 'package:parser_builder/error.dart';
import 'package:parser_builder/fast_build.dart';
import 'package:parser_builder/parser_builder.dart';
import 'package:parser_builder/sequence.dart';
import 'hex_color_parser_helper.dart';
Future<void> main(List<String> args) async {
final context = Context();
const filename = 'example/hex_color_parser.g.dart';
await fastBuild(context, [_parse], filename,
partOf: 'hex_color_parser.dart', publish: {'parse': _parse});
}
const _hexColor = Named(
'_hexColor',
Nested(
'hexadecimal color',
Preceded(
Tag('#'),
Indicate(
'A hexadecimal color starting with "#" must be followed by 6 hexadecimal digits',
Map3(
_hexPrimary,
_hexPrimary,
_hexPrimary,
ExpressionAction<Color>(
['r', 'g', 'b'], 'Color({{r}}, {{g}}, {{b}})'))))));
const _hexPrimary = Named(
'_hexPrimary',
Map1(TakeWhileMN(2, 2, CharClass('[0-9A-Fa-f]')),
ExpressionAction<int>(['x'], 'int.parse({{x}}, radix: 16)')));
const _parse = Named('_parse', _hexColor);