Comments (4)
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.
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.
@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.
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)
- [proposed labels: question, feature request] best practices for stateful matching of simple patterns HOT 4
- Question: mergeError HOT 2
- Greedy combinators HOT 11
- Problematic `IsString` instance HOT 4
- Processing input prior to parsing while retaining source positions HOT 1
- Mention in documentation that `parse` is an alias for `runParser` HOT 1
- MonadAccum instance for ParsecT HOT 5
- Tabs are not handled correctly when errors are rendered HOT 4
- Indentation error lost in alternative HOT 3
- `local` clears all hints HOT 5
- 9.4 migration: getSourcePos now requires `Monad m =>` HOT 6
- Remove/upgrade version bounds of executable `test-debug` from megaparsec-tests HOT 2
- Add `drop` to `Text.Megaparsec` HOT 3
- Wrong source locations on `unexpected end of input` with custom tokens HOT 2
- get col, row (as Int's) and error message of the first TrivialError HOT 2
- deepseq-1.5? HOT 1
- Error context with additional source positions HOT 4
- Parsing hexadecimal floats HOT 1
- Rewrite rules for parser primitives HOT 1
- How to use `Operator` from tutorial HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from megaparsec.