combinator 1.0.0-beta+7 copy "combinator: ^1.0.0-beta+7" to clipboard
combinator: ^1.0.0-beta+7 copied to clipboard

outdated

Parser combinators that support static typing, file spans, and more.

example/main.dart

import 'dart:io';
import 'package:combinator/combinator.dart';
import 'package:string_scanner/string_scanner.dart';

final Parser minus = match('-');

final Parser<int> digit = match(
  new RegExp(r'[0-9]'),
  errorMessage: 'Expected a number',
);

final Parser digits = digit.plus();

final Parser separator = match('.');

final Parser decimal = digits.then((separator.then(digits)).opt());

final Parser number =
    minus.opt().then(decimal).map<num>((r) => num.parse(r.span.text));

main() {
  while (true) {
    stdout.write('Enter a number: ');
    var line = stdin.readLineSync();
    var scanner = new SpanScanner(line, sourceUrl: 'stdin');
    var result = number.parse(scanner);

    if (!result.successful) {
      for (var error in result.errors) {
        stderr.writeln(error.toolString);
        stderr.writeln(error.span.highlight(color: true));
      }
    } else
      print(result.value);
  }
}
1
likes
0
points
207
downloads

Publisher

unverified uploader

Weekly Downloads

Parser combinators that support static typing, file spans, and more.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

matcher, source_span, string_scanner

More

Packages that depend on combinator