gluon
gluon copied to clipboard
[WIP] feat(std): replace parser lib with more generic version
Description
Adds a Parsable interface and a parser combinator library based on it to replace the current one.
Related PRs
Depends on #686.
Similar concept to the Streamlike interface (#737)
Status
In Development
Outstanding design questions:
- [x] ~~How should parser handle errors and custom error types?~~ (It will use its own error type. No customization for now.)
- [ ] How to cleanly handle types that don't naturally lend themselves to StateT sequencing (String and Array)? (Most likely a wrapper, like in the current parser.)
To Do
- [x] Get StateT to a run without errors to begin debugging.
- [ ] Add useful functions
- [ ] Add implementations for standard types
- [ ] Add inline documentation
- [ ] Add documentation in the book?
Prior art
- Revisiting 'Monadic Parsing in Haskell' and yoctoparsec
- nom
- Megaparsec
Future Possibilities
- Build
Parsableon top ofStreamlikeor otherwise take advantage of their relatedness. Indexable->Parsable?
Ignore std/parser.glu for now. It's still a mess.
But what do you think of the Alternative implementation for Result? I think it makes sense.
But what do you think of the Alternative implementation for Result? I think it makes sense.
It doesn't seem to compile as is :( . Searched for what Haskell does with its equivalent Either type and there doesn't seem to be a way to construct such as an instance https://stackoverflow.com/questions/44472008/why-is-there-no-alternative-instance-for-either-but-a-semigroup-that-behaves-sim
Sorry. It didn't compile because I wrote it wrong the first time. Alternative (Result (m e)) seems to work now.
If I understand correctly, the answerer of that question says that Alternative can't be implemented for Either because Haskell doesn't allow you to add constraints to the instantiation that don't exist in the definition (maybe that requires an extension?).
While it is possible to construct a type where
ehas an instance ofAlternativeyou can't make an instance forAlternativeforEitherwith thatebecause no such constraint is in the type class definition (something along the lines of:(Alternative e, Applicative (f e)) => Alternative (f e)).
But doing so works just fine in Gluon.