I have a few technical questions about the internal work of (Mega) Parsec, the informal context of which is:
What is the idea governing the accumulation / distribution of error messages through continuations in Parsec?
In particular: Consider an operation mplusdoing an ParsecTinstance MonadPlus. ( Source )
mplus m nreceives as an input string sfor parsing and continuation of cok, cerr, eokand eerrto follow the results of the analysis.
First execute the syntax swith m:
- If the parsing succeeds and consumes (accordingly does not consume) the part
s, follow the continuation cok(respectively, eok). - When parsing
sa mfailing part using s, be continued cerr. - Suppose parsing
sc mfails without consuming anything; let erris a parsing error associated with this failure. Then we will try to parse swith nand accordingly choose a continuation:- If parsing
swith nsucceeding at input consumption, be continued cok. - If parsing
swith ndoes not work when consuming input, follow the continuation cerr. - If parsing
swith ndoing well without the use of input, be continued neok, resulting from eok:neok y s' err' = eok y s' (mergeError err err') - When parsing
sa nfail without consuming input, follow the continuation neerrobtained from eerr:neerr y s' err' = eerr (mergeError err err')
My question is:
Why do we combine errors by following the โemptyโ continuations, and not following the โconsumedโ continuation, thereby forgetting about all previous errors?
It should be a design decision, but I can not understand the reasons for this. Maybe a simple example that will clarify this?
source
share