petitparser / dart-petitparser

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

use petitparser to recognize jsonDecode output #163

Open RandalSchwartz opened 10 months ago

RandalSchwartz commented 10 months ago

I still occasionally think that I can use petitparser to construct a "lexer" and "grammar" for parsing a decodeJson object tree and map it into richer dart objects. The problem is that decodeJson gives me a tree, not a String. Is there a way to use all the wonderful combining and choosing parts of the grammars to essentially "recognize" the shape of a tree, and then map it into Dart objects at each level?

renggli commented 10 months ago

Earlier versions of PetitParser could parse over arbitrary lists of (nested) objects. There are two main reasons I removed support: (1) there was no demand for it, you are in fact the first one to ever ask for this; and (2) supporting it comes at the cost of added complexity and a loss of performance (in Dart String and List do not have a shared interface).

If you want to play around with this try v1.7.7, the last version that supported this feature. You'll see that through the code there are numerous checks if the parsed input is a String or not.