GithubHelp home page GithubHelp logo

Comments (3)

aslatter avatar aslatter commented on June 16, 2024

I guess I'm ambivalent, here. It's definitely surprising behavior.

It might be in the "so old it's not a bug" bucket, however if this would break any parser I'm not even sure what they would look like.

from parsec.

abooij avatar abooij commented on June 16, 2024

I recently wasted some time trying to understand why notFollowedBy . notFollowedBy is not equal to lookAhead (particularly, I had a line of code that said "notFollowedBy eof" which IMHO makes a lot of sense). I think this behavior, while unfortunate, is acceptable, but should at least be documented.

from parsec.

mrkkrp avatar mrkkrp commented on June 16, 2024

@tulcod, FYI this is fixed in Megaparsec. See here how it works. The examples (and upcoming tests) include notFollowedBy . notFollowedBy = lookAhead property and notFollowedBy eof works just like you would expect.

This particular combinator can be borrowed by Parsec if it's placed in Text.Parsec.Prim module, since I've written it as a primitive combinator, Parsec version would be:

-- | @notFollowedBy p@ only succeeds when parser @p@ fails. This parser
-- does not consume any input and can be used to implement the “longest
-- match” rule.

notFollowedBy :: Stream s m t => ParsecT s u m a -> ParsecT s u m ()
notFollowedBy p = ParsecT $ \s@(State input pos _) _ _ eok eerr -> do
  let cok' _ _ _ = eerr $ newErrorUnknown pos
      cerr'    _ = eok () s $ newErrorUnknown pos
      eok' _ _ _ = eerr $ newErrorUnknown pos
      eerr'    _ = eok () s $ newErrorUnknown pos
  unParser p s cok' cerr' eok' eerr'

Well, this is a bit more primitive than Megaparsec version… To match quality of Megaparsec error messages some additional work is required, so error messages will differ from those I posted.

from parsec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.