94 questions
2
votes
1
answer
81
views
How to make the entire Parsec parsing process fail upon certain conditions?
I'm creating a toy language in Haskell, and using Text.Parsec to parse everything, So far it's worked great, but there's a certain feature that I don't know how to implement:
What I want to implement: ...
1
vote
1
answer
104
views
Hoisting the ParsecT monad transformer in Megaparsec
type P = ParsecT Void String (ReaderT UI IO) UI
type Q = ParsecT Void String ((->) UI) (UI -> UI,String)
I know how to do this:
type Q' = ParsecT Void String ((->) UI) (UI,String)
qtoq' p = ...
0
votes
1
answer
96
views
Why does combination of some and many in Megaparsec lead to infinite recursion?
I've tried
ghci> :m +Text.Megaparsec
ghci> :m +Data.Void
ghci> :m +System.Timeout
ghci> :m +Text.Megaparsec.Char
ghci> timeout (15*10^(6::Int)) $ parseTest (some (many digitChar :: ...
1
vote
1
answer
116
views
How to turn a function into a parser in haskell (Megaparsec)
This is my current code for multiplying the first and last numbers in a string
type Parser = Parsec Void String
parsefirst :: Parser Int
parsefirst = do
getnotdigits
x <- some digitChar
...
3
votes
1
answer
197
views
Understanding many in Megaparsec
I am trying to understand the behavior of many in the Megaparsec library for Haskell. I would have thought that many returns an empty list when its input parser fails, but this does not seem to be the ...
4
votes
1
answer
195
views
Haskell Megaparsec: how to show a traceback of all parsers that led up to an error?
Here's my toy file:
import Text.Megaparsec
import Text.Megaparsec.Char
import Data.Void (Void)
type Parser = Parsec Void String
myParser :: Parser String
myParser = do
d <- digitChar
...
2
votes
2
answers
364
views
Parsing inside `between` with Megaparsec
I am writing a parser for a markdown-like document format. I want to be able to match something like ^[some *formatted* text] as a footnote in my syntax definition. Here's a minimal example:
{- cabal:
...
3
votes
1
answer
123
views
Parse many terms not followed by symbol
I am attempting to develop a lambda calculus interpreter, which supports definitions of terms. For that, I'm using the Megaparsec library in Haskell.
I have the following grammar:
term := var | lambda ...
0
votes
1
answer
73
views
How can I access the whole input from an arbitrary parser in a sequence?
I'm working through a DNS message parser. I have defined the following using megaparsec:
Header
data DNSHeader = DNSHeader
{ hid :: !Word16,
hflags :: !Word16,
hnumQuestions :: !Word16,
...
2
votes
1
answer
227
views
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 ...
2
votes
2
answers
113
views
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 '-' <*> ...
1
vote
1
answer
501
views
Megaparsec parse many until given marker with backtracking
I'm trying to parse the following input using megaparsec (if this sounds familiar to the advent of code challenge from day 7 2022, it's because it is):
$ cd /
$ ls
dir a
123 foo.txt
dir d
$ cd a
$ ls
...
0
votes
2
answers
424
views
How to parse Number with comma via Megaparsec
Currently I have a parser:
pScientific :: Parser Scientific
pScientific = lexeme L.scientific
This is able to easily parse something like 4087.00
but fails when then number 4,087.00 Is there a way to ...
0
votes
1
answer
465
views
Megaparsec .. Find an Element Before Encountering a Different Element
I am trying to parse (using magaparsec) the XML export
of FreePlane (mindmapper).
This is my third attempt to really 'learn' (internalize)
megaparsec. I've written several parsers before, two
worked (...
0
votes
1
answer
149
views
Megaparsec: transforming comment syntax into a Record
Using Megaparsec, if I want to parse a string containing comments of the form ~{content} into a Comment record, how would I go about doing that? For instance:
data Comment = { id :: Integer, content ::...