Closed floyd-may closed 1 year ago
If val
is from pLeft
, then you already know what val
would be, why do you need to create pRight
from val
?
You can't know val
until runtime when the parser is executing. Let's say we want to parse the following:
A leading
count
followed by exactlycount
instances of a word (parsed bypWord
). Some examples of valid input would be:
3 word thing stuff
5 a short little word pile
and invalid input would be:3 too few
2 too many words
In parsec or fparsec, you could parse this with pint >>= fun count -> parray count pWord
(roughly, where parray
is similar to rep_n
). The intent here is to dynamically generate the parser at runtime via pRightApply
based on the value of val
at runtime.
I see, so what you want is a context sensitive syntax. It looks useful. I will use that as a unit test.
In parsec and fparsec, you can use the
>>=
operator (monadic bind) to use the parsed result from a parser to produce a new parser. There doesn't appear to be equivalent functionality intypescript-parsec
. I propose the addition of a new combinatorcombine
(since bind might be confusing to experienced javascript programmers):