GithubHelp home page GithubHelp logo

Comments (4)

mrkkrp avatar mrkkrp commented on May 29, 2024

Right now it looks like this is

  • project-specific (have you seen such a feature in any other library of this sort?);
  • easy to implement.

So I guess it falls into the category of things that should be done by author of concrete project, not provided by library.

Do you know that Megaparsec has different approach when it comes to parsing of languages? Instead of exceptionally inflexible Text.Parsec.Token we have Text.Megaparsec.Lexer.

This module doesn't lock you into any sort of parsing strategy and doesn't impose anything. One good thing about it is that you can control what white space is on per-lexeme basis. The module provides space function which constructs parser that consumes white space. It looks like this:

space :: MonadParsec s m Char
      => m () -- ^ A parser for a space character (e.g. 'C.spaceChar')
      -> m () -- ^ A parser for a line comment (e.g. 'skipLineComment')
      -> m () -- ^ A parser for a block comment (e.g. 'skipBlockComment')
      -> m ()
space ch line block = hidden . skipMany $ choice [ch, line, block]

This parser (or other parser if needed) is used to define lexeme and other functions. From conceptual point of view, space defines what is considered white space. The function itself is a helper, you can write your own variation that also takes pragmas into consideration, that's quite easy. This way you won't have to work on lower level of abstraction often.

You can then use something like WriterT in combination with ParsecT to accumulate encountered pragmas. You can wrap ParsecT in WriterT if you want backtracking WriterT (all tools in Megaparsec work with any instance of MonadParsec, not only ParsecT, and WriterT is instance of MonadParsec out of box, so it's all easy).

I don't see reason to include this sort of feature right now, closing. Feel free to comment if you think I'm mistaken.

from megaparsec.

Toxaris avatar Toxaris commented on May 29, 2024

Yes I understand that this sort of thing is already easier in megaparsec than in parsec. That's why I'm excited about megaparsec :)

I posted this feature request because the megaparsec announcement on the haskell-cafe mailing list said:

If you ever had any ideas about what Parsec should've done differently, or
what amazing new combinators it should include, etc., post your ideas here:

from megaparsec.

mrkkrp avatar mrkkrp commented on May 29, 2024

@Toxaris, Yes, thank you, it's absolutely OK! Actually, when I started to work on Megaparsec I studied all existing issues of Parsec (on GitHub and elsewhere) to find out what should be improved (later, but before initial release, some people began to come here and open issues — that improved the project a lot). I think Megaparsec is hopefully a bit better than Parsec mostly because there are people, active users, who express their opinions on what can be improved.

from megaparsec.

Toxaris avatar Toxaris commented on May 29, 2024

Ok great :)

Note that {-# LINE ... #-} pragmas are harder to support than other pragmas because they have to use something like setPosition so that syntax errors after the pragma are reported correctly. So the idea of just collecting all pragmas to be handled later is not sufficient here. On the other hand, {-# LINE ... #-} pragmas are also easier to support generically than other pragmas because using setPosition is often the only thing they need to do, independently of what language you're parsing.

I guess I just want a library (megaparsec or other) which exports something like

skipHaskellBlockCommentButProcessLinePragma :: MonadParsec s m Char => m ()

to be used with space.

from megaparsec.

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.