<div dir="ltr">I'm working with "lookAhead" in Parsec.<div><br></div><div>My goal is to simplify error messages and make them more relevant. I'm parsing strings that represent musical score text markings that convey nuances of playback expression. I worked long and hard to devise a concise syntax that has sufficient expressive power --- must be concise because there is little room in these score for text markings, especially if there are a lot of them. The result is that it looks a little cryptic.</div><div><br></div><div>1;%2|></div><div><br></div><div><%4|</div><div><br></div><div><<5:4</div><div><br></div><div><<5:4a</div><div><br></div><div>etc.</div><div><br></div><div>My first parser worked, but would give error messages like</div><div><br></div><div>"Unexpected ';', expected digit, ';', '%', '<<', '|', ....</div><div><br></div><div>etc., basically giving me no clue what the parser was thinking.</div><div><br></div><div>The first challenge is that it's hard to identify the particular type of mark from the first few characters. For instance, a mark like this "1;%2|>" --- what gives it away is the ">" at the very end. That means it's a "right-facing warp" and that defines what to expect in the other characters. So it would be great if my parser first identified this as a "right-facing warp" and then when parsing the internals it can give messages that make sense in context.</div><div><br></div><div>So I tried this, with lookAhead</div><div><br></div><div>rightWarp = do</div><div>  try (lookAhead (do many1 (noneOf "<>")</div><div>                                char '>'</div><div>                                eof))</div><div>  ... parse internals ...</div><div>  char '>'</div><div>  eof</div><div><br></div><div>The problem is that I want to put a <?> message in here somewhere so that if this whole 'rightWarp' parser fails, it will say "expected right warp".  But I have found with experiment that the parser considers the point of failure to be in different places inside the lookAhead. For instance if I give an input string that has too many characters at the end, the failure point will be the 'eof' inside the lookAhead. If I put a <?> message anywhere else, the parser will just say "expected end of input". On the other hand, if there is no '>' character, then the failure point will be "char '>'" and the message will be "expected >". </div><div><br></div><div>What I was hoping was that there was some single place I could put a <?> message that would say "expected right warp" no matter where inside rightWarp the failure point occurs.</div><div><br></div><div>Any ideas?</div><div><br></div><div>Mike</div><div><br></div><div><br></div><div><br></div><div><br></div></div>