parsers 0.9.2 copy "parsers: ^0.9.2" to clipboard
parsers: ^0.9.2 copied to clipboard

outdatedDart 1 only

Parser combinators for Dart.

Parser Combinators for Dart #

Check out the user guide (work in progress).

Quick Start #

pubspec.yaml

name: demo
dependencies:
  parsers: any

bin/demo.dart

import 'package:parsers/parsers.dart';
import 'dart:math';

final number = digit.many1       ^ digits2int
             | string('none')    ^ none
             | string('answer')  ^ answer;

final comma = char(',') < spaces;

final numbers = number.sepBy(comma) < eof;


digits2int(digits) => parseInt(Strings.concatAll(digits));
none(_) => null;
answer(_) => 42;


main() {
  print(numbers.parse('0,1, none, 3,answer')); // [0, 1, null, 3, 42]
  print(numbers.parse('0,1, boom, 3,answer')); // line 1, character 6: expected digit, 'none' or 'answer', got 'b'.
}

See the example directory for advanced usage.

About #

This library is heavily inspired by Parsec, but differs on some points. In particular, the | operator has a sane backtracking semantics, as in Polyparse. As a consequence it is slower but also easier to use. I've also introduced some syntax for transforming parsing results that doesn't require any knowledge of monads or applicative functors and features uncurried functions, which are nicer-looking than curried ones in Dart.

0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Parser combinators for Dart.

Homepage

License

unknown (LICENSE)

Dependencies

persistent, unittest

More

Packages that depend on parsers