petitparser / dart-petitparser

Dynamic parser combinators in Dart.
https://pub.dartlang.org/packages/petitparser
MIT License
453 stars 47 forks source link

NoSuchMethodError: Class 'SequenceParser<dynamic>' has no instance method '&'. #170

Closed leeflix closed 3 months ago

leeflix commented 3 months ago

i would like to use the following extension:

extension on String {
  operator &(Parser p) => string(this) & p;
}

but i get the error NoSuchMethodError: Class 'SequenceParser<dynamic>' has no instance method '&'. when using it. any ideas how to fix?

renggli commented 3 months ago

Mhh, the following code works for me:

import 'package:petitparser/petitparser.dart';

extension on String {
  operator &(Parser p) => string(this) & p;
}

void main(List<String> arguments) {
  final parser = 'a' & string('b');
  print(parser.parse('ab')); // Success[1:3]: [a, b]
}

Can you provide a minimally reproducible example?

leeflix commented 3 months ago

fixed it