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
3
votes
2 answers

How far does "try" back track?

So ... I messed up a recording in CSV format: 23,95489,0,20,9888 Due to language settings floating point numbers were written with commas as seperator ... in a comma separated value file ... Problem is that the file does not have a nice formatting…
fho
  • 6,787
  • 26
  • 71
3
votes
0 answers

How to parse string literal in Megaparsec?

So I've spent some time reading the docs but for anything but the most basic of languages the tutorials aren't enough and it's hard to go through the whole docs of the language. I get lost too easily. How would I create a "&"#someStringUtf8"…
ditoslav
  • 4,563
  • 10
  • 47
  • 79
3
votes
1 answer

multiple errors with different positions using megaparsec

I'm going to use megaparsec for parsing a programming language for university project. However, I searched for finding a way to report multiple errors. I know about withRecovery and I saw this issue but I didn't find about the case where errors…
niceman
  • 2,653
  • 29
  • 57
3
votes
1 answer

Parsing many blocks with foldLine

For this simplified problem, I am trying to parse an input that looks like foo bar baz quux woo hoo xyzzy glulx into [["foo", "bar", "baz", "quux", "woo"], ["hoo", "xyzzy", "glulx"]] The code I've tried is as follows: import qualified…
Cactus
  • 27,075
  • 9
  • 69
  • 149
2
votes
1 answer

Using makeExprParser with ambiguity

I'm currently encountering a problem while translating a parser from a CFG-based tool (antlr) to Megaparsec. The grammar contains lists of expressions (handled with makeExprParser) that are enclosed in brackets (<, >) and separated by ,. Stuff like…
user1512263
  • 217
  • 1
  • 7
2
votes
2 answers

How to parse a character range into a tuple

I want to parse strings like "0-9" into ('0', '9') but I think my two attempts look a bit clumsy. numRange :: Parser (Char, Char) numRange = (,) <$> digitChar <* char '-' <*> digitChar numRange' :: Parser (Char, Char) numRange' = liftM2 (,)…
Good Night Nerd Pride
  • 8,245
  • 4
  • 49
  • 65
2
votes
0 answers

How to Group and Split Monad Transformers using Identity

I am currently learning about Monad Transformers and noticed that the MonadTrans class that the library I am using (Mageparsec) implements, does not define any way to group and split apart the Transformer, where I would expect these functions to…
user13507303
2
votes
1 answer

Permutation parsing with megaparsec + parser-combinators too lenient

I'm attempting to parse permutations of flags. The behavior I want is "one or more flags in any order, without repetition". I'm using the following packages: megaparsec parser-combinators The code I have is outputting what I want, but is too…
danielbeard
  • 9,120
  • 3
  • 44
  • 58
2
votes
2 answers

How do I convert a MegaParsec "ParseErrorBundle" into a list of "SourcePos" and error messages

Using the MegaParsec parse function, I'm able to run a parser, and get a ParseErrorBundle if it fails. I know that I'm able to pretty print the ParseErrorBundle, and get an error message for the entire parse failure, which will include the line and…
Joe
  • 1,479
  • 13
  • 22
2
votes
1 answer

Issue when parsing array[1][2] using Megaparsec

I was following Megaparsec documentation to parse multidimensional array. opSubscript = Postfix $ foldr1 (.) <$> some singleIndex singleIndex = do index < brackets expr return $ \l -> ArrayIndex l index array[1][2] is expected to be parsed…
sinoTrinity
  • 1,125
  • 2
  • 15
  • 27
2
votes
1 answer

Possible to read files in pure code in Haskell?

I am writing a compiler for a DSL. After reading the source file into a string, all the rest steps (parsing, type checking, and codegen) are all pure code, transforming the code from one representation to another. All is good till there are…
sinoTrinity
  • 1,125
  • 2
  • 15
  • 27
2
votes
1 answer

avoid parsing last separator with `sepBy`

I'm trying to parse a string using megaparsec. Part of it is a repetition of strings separated by a separator and I'm using sepBy for this. Consider for example sepBy (char 'a') (char 's') This parses correctly "", "a", "asa", ... The problem…
marcosh
  • 8,780
  • 5
  • 44
  • 74
2
votes
1 answer

My Megaparsec parser gets stuck and ghci debugging isn't helping either

I have worked through this Megaparsec tutorial and am trying now to write my own parser based on that. I want so write a simple parser for a made-up assembly language: Label: lda $0ffe sta %10100110 push $01, $02, $03 This are the…
koalag
  • 133
  • 1
  • 16
2
votes
2 answers

How to make a sub parser with Parsec?

I would like to parse several lists of commands indented or formated as array with Parsec. As example, my lists will be formated like this: Command1 arg1 arg2 Command1 arg1 arg2 Command1 arg1 arg2 Command2 arg1 …
JeanJouX
  • 2,555
  • 1
  • 25
  • 37
2
votes
1 answer

Errorbundles after parsing with megaparsec

I currently have a working parser in megaparsec, where I build an AST for my program. I now want to do some weeding operations on my AST, while being able to use the same kind of pretty errors as the parser. While this stage is after parsing, I'm…
Allan W
  • 2,791
  • 4
  • 23
  • 41