Questions tagged [megaparsec]

Megaparsec is a monadic parser combinator library for Haskell with improved error reporting and indentation-aware parsing

Megaparsec is a monadic parser combinator library for Haskell. It is based on Parsec and provides improved error reporting and indentation-aware parsing.

87 questions
0
votes
1 answer

Why `optional` in a Parser can err out

https://github.com/complyue/dcp is a minimum working example to reprod this error $ cabal run dcp:dcp < samples/basic.txt Up to date dcp: 10:1: | 10 | method doXXX() pass | ^ unexpected 'm' expecting ';' CallStack (from HasCallStack): …
Compl Yue
  • 164
  • 1
  • 3
  • 16
0
votes
1 answer

How to correctly parse field access after function call via parser-combinators (makeExprParser) library?

I want to parse expressions like this: a().x. It should look like EAttrRef (EFuncCall (EVarRef "a") []) "x". Unfortunately my expression parser is stopping too soon, it only parses a() and then stops. 1:4: | 1 | a().x | ^ unexpected…
menfon
  • 1,587
  • 1
  • 11
  • 28
0
votes
1 answer

Different results produced by stack runghc vs stack ghci Haskell

I'm writing a parser using Megaparsec. Basically, the main file will open and read content of a file and then parsing that content. When running the main file in ghci, everything was produced correctly img-1 But when I tried running the Main file…
Duy Phan
  • 27
  • 5
0
votes
1 answer

How to overload operator in Parsec/Megaparsec?

I am implementing a compiler using Parsec/Megaparsec as parser. I can't find a way to overload operator +, which I want to use for both integer addition and string concatenation. Is it possible?
sinoTrinity
  • 1,125
  • 2
  • 15
  • 27
0
votes
1 answer

Using parseTest in megaparsec 7.0.4

Advent of Code means I'm using megaparsec for the first time in a while. And things have changed around a fair bit since last time. Assuming import qualified Text.Megaparsec as MP import qualified Text.Megaparsec.Char as C I tried MP.parseTest…
Julian Birch
  • 2,605
  • 1
  • 21
  • 36
0
votes
0 answers

megaparsec reports incorrect location on parse error

For this project I'm parsing in two stages. The first stage handles include/ifdef/define directives and chunks the input up into [Span] items which define their start/end points in the original inputs along with the body text. This stream is then…
Brian Magnuson
  • 1,487
  • 1
  • 9
  • 15
0
votes
4 answers

Parsing optional recursive parser runs in infinite recursion

I'm currently writing a parser for ECMAScript 5 (as a toy). The standard dictates how logical or expressions should be parsed: : || basicly this is…
Jan van Brügge
  • 742
  • 8
  • 13
0
votes
2 answers

how to use megaparsec's combinators on StateT

I'm building a compiler for java for university project, in my project my parsers are mostly StateT (Scope,SymbolTable) String m a where Scope is the scope we're at now(method,class,etc) and SymbolTable holds the symbols defined till now. I wanted…
niceman
  • 2,653
  • 29
  • 57
0
votes
1 answer

Use Parsec to write a new function "parse :: String -> Stm"

I have a coursework that requires me to write a new function parse:: String -> Stm. Parsec already has a parse function, so I'm supposed to import qualified parsec so that parse returns my wrapper function. The wrapper function needs to parse the…
Adey
  • 3
  • 1
0
votes
1 answer

Can I easily wrap attoparsec in transformer?

I want to write code doing something like C preprocessing. So I looked for libraries and got two candidates, attoparsec, megaparsec. I need the feature reporting error position and megaparsec already has that. But attoparsec would be desirable for…
0
votes
0 answers

Megaparsec: macro expansion during parsing

In a small DSL, I'm parsing macro definitions, similarly to #define C pre-processor directives (here a simplistic example): _def mymacro(a,b) = a + b / a When the following call is encountered by the parser c = mymacro(pow(10,2),3) it is expanded…
cornuz
  • 2,678
  • 18
  • 35
0
votes
2 answers

Grouping lines with Parsec

I have a line-based text format I want to parse with Parsec†. A line either starts with a pound sign and specifies a key value pair separated by a colon or is a URL that is described by the previous tags. Here's a short…
passy
  • 7,170
  • 5
  • 36
  • 38
1 2 3 4 5
6