parsec

Cannot compute minimal length of a parser - uu-parsinglib in Haskell

China☆狼群 提交于 2020-01-02 04:42:08
问题 Lets see the code snippet: pSegmentBegin p i = pIndentExact i *> ((:) <$> p i <*> ((pEOL *> pSegment p i) <|> pure [])) if I change this code in my parser to: pSegmentBegin p i = do pIndentExact i ((:) <$> p i <*> ((pEOL *> pSegment p i) <|> pure [])) I've got an error: canot compute minmal length of a parser due to occurrence of a moadic bind, use addLength to override I thought the above parser should behave the same way. Why this error can occur? EDIT The above example is very simple (to

Haskell Parsec Parser for Encountering […]

柔情痞子 提交于 2020-01-02 03:29:07
问题 I'm attempting to write a parser in Haskell using Parsec. Currently I have a program that can parse test x [1,2,3] end The code that does this is given as follows testParser = do { reserved "test"; v <- identifier; symbol "["; l <- sepBy natural commaSep; symbol "]"; p <- pParser; return $ Test v (List l) p } <?> "end" where commaSep is defined as commaSep = skipMany1 (space <|> char ',') Now is there some way for me to parse a similar statement, specifically: test x [1...3] end Being new to

How to parse a Tuple (String,Int) in Haskell using parsec

筅森魡賤 提交于 2019-12-31 07:31:47
问题 I think i already managed to parse strings to strings and strings to Ints but I also need to parse a (String,Int) type as userRatings is in order to read from a textFile correctly and I am using Parsec This is the Parsing along with the import import Text.Parsec ( Parsec, ParseError, parse -- Types and parser , between, noneOf, sepBy, many1 -- Combinators , char, spaces, digit, newline -- Simple parsers ) -- Parse a string to a string stringLit :: Parsec String u String stringLit = between

How to parse a Tuple (String,Int) in Haskell using parsec

核能气质少年 提交于 2019-12-31 07:31:45
问题 I think i already managed to parse strings to strings and strings to Ints but I also need to parse a (String,Int) type as userRatings is in order to read from a textFile correctly and I am using Parsec This is the Parsing along with the import import Text.Parsec ( Parsec, ParseError, parse -- Types and parser , between, noneOf, sepBy, many1 -- Combinators , char, spaces, digit, newline -- Simple parsers ) -- Parse a string to a string stringLit :: Parsec String u String stringLit = between

Parsec vs Yacc/Bison/Antlr: Why and when to use Parsec?

╄→尐↘猪︶ㄣ 提交于 2019-12-28 07:58:39
问题 I'm new to Haskell and Parsec. After reading Chapter 16 Using Parsec of Real World Haskell, a question appeared in my mind: Why and when is Parsec better than other parser generators like Yacc/Bison/Antlr? My understanding is that Parsec creates a nice DSL of writing parsers and Haskell makes it very easy and expressive. But parsing is such a standard/popular technology that deserves its own language, which outputs to multiple target languages. So when shall we use Parsec instead of, say,

Parsing single qoute char in a single-quoted string in parsec

ε祈祈猫儿з 提交于 2019-12-25 03:27:18
问题 I've got a silly situation in my parsec parsers that I would like your help on. I need to parse a sequence of strongs / chars that are separated by | characters. So, we could have a|b|'c'|'abcd' which should be turned into [a,b,c,abcd] Space is not allowed, unless inside of a ' ' string. Now, in my naïve attempt, I got the situation now where I can parse strings like a'a|'bb' to [a'a,bb] but not aa|'b'b' to [aa,b'b]. singleQuotedChar :: Parser Char singleQuotedChar = noneOf "'" <|> try

Parsing single qoute char in a single-quoted string in parsec

非 Y 不嫁゛ 提交于 2019-12-25 03:27:09
问题 I've got a silly situation in my parsec parsers that I would like your help on. I need to parse a sequence of strongs / chars that are separated by | characters. So, we could have a|b|'c'|'abcd' which should be turned into [a,b,c,abcd] Space is not allowed, unless inside of a ' ' string. Now, in my naïve attempt, I got the situation now where I can parse strings like a'a|'bb' to [a'a,bb] but not aa|'b'b' to [aa,b'b]. singleQuotedChar :: Parser Char singleQuotedChar = noneOf "'" <|> try

Haskell Parsec accounting for multiple expression occrrences in grammar

笑着哭i 提交于 2019-12-25 01:54:10
问题 I have been trying to create a parser using details from the following tutorial much of the code is copied directly from the tutorial with only a few names changed. import qualified Text.ParserCombinators.Parsec.Token as P reserved = P.reserved lexer integer = P.integer lexer whiteSpace = P.whiteSpace lexer identifier = P.identifier lexer data Express = Seq [Express] | ID String | Num Integer | BoolConst Bool deriving (Show) whileParser :: Parser Express whileParser = whiteSpace >> expr7

Applicative style parser for constructor with two arguments

拟墨画扇 提交于 2019-12-24 00:15:04
问题 I want to write a parser for a comma separated pair of values in angle brackets. I got it to work with the following approach: pair p1 p2 = do x1 <- p1 comma x2 <- p2 return (x1, x2) data Foo = Foo (Bar, Bar) foo :: Parser Foo foo = Foo <$> (angles $ pair bar bar) However I would prefer the Foo constructor to take two parameter rather than a tuple: data Foo = Foo Bar Bar What is the best way to write such a parser? Ideally I would like to reuse standard Parsec parsers such a angles and use

How would I strip out comments from a file with Parsec?

。_饼干妹妹 提交于 2019-12-23 19:58:30
问题 I have this much: comment :: GenParser Char st () comment = (string "--" >> manyTill anyChar newline >> spaces >> return ()) <|> (string "/*" >> manyTill anyChar (string "*/") >> spaces >> return ()) eatComments :: GenParser Char st String eatComments = do xs <- many (do optional comment x <- manyTill anyChar (try comment) return x) return $ intercalate " " xs This works if the input ends with a comment, but it fails if it ends with something else. In that case the error message is like No