FAQ Database Discussion Community


Problems with Applicative-style Parsec

haskell,parsec
I have the following ADT: type Program = [Expr] data Expr = Num Int | Bool Bool | Binding String Expr deriving (Show) Here's a parser for variable-binding expressions, of the form lhs is rhs. binding :: Parser Expr binding = do lhs <- word spaces string "is" spaces rhs...

Parsec <|> choice in parser, Error throws but does not go to next parser

parsing,haskell,parsec
I am learning haskell with Write yourself a scheme. I am currently trying to implement a char recognition in scheme. A char is #\<character> or #\<character-name> like #\a or #\ or #\space. So i wrote the following code : -- .. some code .. data LispVal = Atom String |...

How to manually manipulate precedence of special expressions in Parsec?

haskell,compiler-construction,interpreter,parsec,lambda-calculus
I tried to write a parser for a lambda-calculus interpreter that uses the expression closures grammars of JavaScript 1.8, which means function(x) x * x same with function(x) { return x * x; }. Here is my parser code. module Parser where import Text.Parsec import Text.Parsec.String import qualified Text.Parsec.Token as...

How do you parse an Intel Hex Record with applicative functors using the haskell parsec library?

haskell,parsec
I would like to parse an Intel Hex Record with parsec using the applicative functor style. A typical records looks like the following: :10010000214601360121470136007EFE09D2190140 The first character is always ':', the next two characters are a hex string representing the number of bytes in the record. The next four characters...

ghc-7.10: Non type-variable argument (Use FlexibleContexts to permit this)

haskell,ghc,parsec
I was trying to use ghc-7.10 (RC 2) and got this message in a number of cases, e.g., src/Text/Regex/XMLSchema/Generic/RegexParser.hs:439:5: Non type-variable argument in the constraint: Text.Parsec.Prim.Stream s m Char (Use FlexibleContexts to permit this) When checking that ‘prop’ has the inferred type prop :: forall s u (m :: *...

Composing optional Aeson parsers

haskell,monads,composition,parsec,aeson
Here is a part of JSON object which represents the user: { "image": { "url": "http://example.com" } } I need to parse it into a User type: data User = User { imgUrl :: Maybe Text } The naive solution: parseJSON (Object o) = User <$> getImgUrl o where getImgUrl...

Why do I get “unexpected end of input” when my parser is explicitly looking for it?

haskell,parsec
import Control.Applicative hiding (many) import Text.Parsec import Text.Parsec.String lexeme :: Parser a -> Parser a lexeme p = many (oneOf " \n\r") *> p identifier :: Parser String identifier = lexeme $ many1 $ oneOf (['a'..'z'] ++ ['A'..'Z']) operator :: String -> Parser String operator = lexeme . string field...