platform/packages/combinator/example/tuple.dart

15 lines
446 B
Dart
Raw Normal View History

2021-03-17 23:04:36 +00:00
import 'package:combinator/combinator.dart';
import 'package:string_scanner/string_scanner.dart';
void main() {
2021-03-18 00:00:56 +00:00
var pub = match('pub').map((r) => r.span!.text).space();
2021-03-17 23:04:36 +00:00
var dart = match('dart').map((r) => 24).space();
var lang = match('lang').map((r) => true).space();
// Parses a Tuple3<String, int, bool>
var grammar = tuple3(pub, dart, lang);
var scanner = SpanScanner('pub dart lang');
2021-05-02 04:12:43 +00:00
print(grammar.parse(scanner).value);
2021-03-17 23:04:36 +00:00
}