megaparsec

multiple errors with different positions using megaparsec

对着背影说爱祢 提交于 2020-02-22 06:15:13
问题 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 happen on different positions. for example in this java code : class A { public get() // line 3 column 10 { return x // line 5 column 22 } } There are error1 "expected type at line 3 column 10" and error2 "missing semicolon at line 5 column 22" I know

Parsing many blocks with foldLine

血红的双手。 提交于 2019-12-23 17:53:17
问题 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 Text.Megaparsec.Lexer as L import Text.Megaparsec hiding (space) import Text.Megaparsec.Char hiding (space) import Text.Megaparsec.String import Control.Monad (void) import Control.Applicative space :: Parser () space = L.space (void spaceChar) empty empty item

Recursive Parser

回眸只為那壹抹淺笑 提交于 2019-12-23 13:01:16
问题 I need to parse, using Megaparsec a data structure like data Foo = Simple String | Dotted Foo String where I can have alphanumeric strings separated by dots. For example abc should be parsed to Simple "abc" and abc.def to Dotted (Simple "abc") "def" . My parser at the moment is like fooParser :: Parser Foo fooParser = Simple <$> alphaNum <|> do foo <- fooParser constant "." end <- alphaNum pure $ Dotted foo end This works fine for Simple , but it does not parse any Dotted , because the first

Megaparsec: Unable to parse recursive arithmetic string

一笑奈何 提交于 2019-12-13 11:43:23
问题 I'm working on a small parser using Megaparsec and trying to parse arithmetic. -- Arithmetic expressions data Aexp = N Num | V Var | Mult Aexp Aexp | Add Aexp Aexp | Sub Aexp Aexp deriving (Show, Eq, Read) arithParser :: Parser Aexp arithParser = V <$> strParser <|> N <$> numParser <|> Mult <$> arithParser <* tok "*" <*> arithParser --boolParser :: Parser Bexp strParser :: Parser Var strParser = tok "\"" *> some (noneOf ("\n\r\"=[]{},:")) <* tok "\"" numParser :: Parser Num numParser = (some

Megaparsec: Unable to parse recursive arithmetic string

自古美人都是妖i 提交于 2019-12-03 13:56:35
I'm working on a small parser using Megaparsec and trying to parse arithmetic. -- Arithmetic expressions data Aexp = N Num | V Var | Mult Aexp Aexp | Add Aexp Aexp | Sub Aexp Aexp deriving (Show, Eq, Read) arithParser :: Parser Aexp arithParser = V <$> strParser <|> N <$> numParser <|> Mult <$> arithParser <* tok "*" <*> arithParser --boolParser :: Parser Bexp strParser :: Parser Var strParser = tok "\"" *> some (noneOf ("\n\r\"=[]{},:")) <* tok "\"" numParser :: Parser Num numParser = (some (oneOf ['0' .. '9']) >>= return . read) <* whitespace If I run the command Parse arithParser "5*5" "5*5