Skip to content

Commit bd0f8c9

Browse files
committed
feat: use StateEither for parser
Three big changes were made in parser.ts. The first is that the parser is now generic over the stream state type. A basic StringStream has been implemented but most non-string combinators are generic. The second big change is that Stream is a mutable interface. The Stream type requires a take method and an undo method. Take will return some number of inner values from a buffer and keep a history of all previous cursors. Undo will back track to the nth cursor. Take only accepts whole numbers, so the cursor history must monotonically increase. The last big change is that Parser is implemented over the StateEither monad, which is a new one for fun. Some things of note. The standard fail combinator will automatically pop the last cursor. Since Stream is stateful it is enough to simply create a fail parser to undo the last take. This makes take/flatmap the primary combo for creating one off parsers.
1 parent 1bfa7a5 commit bd0f8c9

File tree

2 files changed

+210
-212
lines changed

2 files changed

+210
-212
lines changed

0 commit comments

Comments
 (0)