rumil 0.6.0 copy "rumil: ^0.6.0" to clipboard
rumil: ^0.6.0 copied to clipboard

Parser combinator library for Dart with left recursion, stack-safe trampolining, typed errors, lazy error construction, and sealed ADT design.

example/example.dart

import 'package:rumil/rumil.dart';

void main() {
  // Parse a number
  final number = digit().many1.capture.map(int.parse);
  print(number.run('42')); // Success(42, consumed: 2)

  // Left-associative operator chain
  final add = symbol('+').as<int Function(int, int)>((a, b) => a + b);
  final expr = number.chainl1(add);
  print(expr.run('1+2+3')); // Success(6, consumed: 5)

  // Left-recursive grammar via rule()
  late final Parser<ParseError, int> e;
  e = rule(
    () =>
        defer(
          () => e,
        ).flatMap((l) => char('+').skipThen(number).map((r) => l + r)) |
        number,
  );
  print(e.run('1+2+3')); // Success(6, consumed: 5)
}
0
likes
160
points
581
downloads

Documentation

API reference

Publisher

verified publisherardaproject.org

Weekly Downloads

Parser combinator library for Dart with left recursion, stack-safe trampolining, typed errors, lazy error construction, and sealed ADT design.

Repository (GitHub)
View/report issues

Topics

#parser #combinator #parsing

License

MIT (license)

More

Packages that depend on rumil