parsec

Python implementation of Parsec?

I recently wrote a parser in Python using Ply (it's a python reimplementation of yacc). When I was almost done with the parser I discovered that the grammar I need to parse requires me to do some look up during parsing to inform the lexer. Without doing a look up to inform the lexer I cannot correctly parse the strings in the language....

A good ocaml parser?

Hi, I'm looking for a good ocaml parsing library that isn't a derivative of flex/bison. Ideally, I'd like a monadic combinator library along the lines of parsec, but I can't find anything. I would use haskell, but making llvm bindings for haskell is proving more tiresome than I originally thought. Cheers, Duane ...

Haskell Parsec compile error

I've installed Haskell via the pre built installer v6.8.2. When trying to compile this sample file with GHC module Main where import Text.ParserCombinators.Parsec import System.Environment main :: IO () main = do args <- getArgs putStrLn ("Hello") I get the following error: D:\src\Haskell>ghc -o read read.hs ghc -o read r...

Raise ParseError in Haskell/Parsec

What is the prefered way to raise errors (ParseError) in Parsec? I got some code inside a parser that performs a check and if the check fails a ParseError should be returned (i.e. Left ParseError when running parse). ...

using oneOf in haskell, errors in compiling

Hi, I'm a complete newbie at Haskell. I'm trying to compile this Haskell file I've downloaded but it's giving me some errors. No instance for (Text.Parsec.Prim.Stream s m Char) arising from a use of 'letter' at Parse.lhs:649:26-31 Possible fix: add an instance declaration for (Text.Parsec.Prim.Stream s m Char) In the first argume...

Using Haskell's Parsec to parse a ByteString

I've managed to use Parsec to parse a String, but cannot manage to do the same with a ByteString. How can I make Parsec work with ByteStrings without manually converting them to Strings? I get the feeling this isn't hard to accomplish. Am I wrong? (I'm new to Haskell. ^^) Thanks! ...

With Parsec, how do I parse zero or more foo1 terminated by foo2 and all separated by dot?

What I am trying to do seems pretty simple, but since I am a parsec Haskell newb, the solution is eluding me. I have two parsers, let's say foo1 and foo2 where foo1 can parse a intermedate term and foo2 parses an ending term. Terms are separated by a symbol, ".". Sentences that I need to parse are foo2 foo1.foo2 foo1.foo1.foo2 and ...

Parsec: backtracking not working

I am trying to parse F# type syntax. I started writing an [F]Parsec grammar and ran into problems, so I simplified the grammar down to this: type ::= identifier | type -> type identifier ::= [A-Za-z0-9.`]+ After running into problems with FParsec, I switched to Parsec, since I have a full chapter of a book dedicated to explaining it. ...

How do Scala parser combinators compare to Haskell's Parsec?

I have read that Haskell parser combinators (in Parsec) can parse context sensitive grammars. Is this also true for Scala parser combinators? If so, is this what the "into" (aka ">>") function is for? What are some strengths/weaknesses of Scala's implementation of parser combinators, vs Haskell's? Do they accept the same class of gra...

Haskell parsec parsing a string of items

I have a list that I need to parse where the all but the last element needs to be parsed by one parser, and the last element needs to be parsed by another parser. a = "p1 p1b ... p2" or a = "p2" Originally I tried parser = do parse1 <- many parser1 parse2 <- parser2 return AParse parse1 parse2 The problem is...

parsec-3.1.0 with custom token datatype

parsec-3.1.0 ( http://hackage.haskell.org/package/parsec-3.1.0 ) works with any token type. However there are combinators like Text.Parsec.Char.satisfy that are only defined for Char datatype. There doesn't seem to be any more general counterpart available. Should I define my own versions or did I miss something? Perhaps there are dif...

Can Haskell's Parsec library be used to implement a recursive descent parser with backup?

I've been considering using Haskell's Parsec parsing library to parse a subset of Java as a recursive descent parser as an alternative to more traditional parser-generator solutions like Happy. Parsec seems very easy to use, and parse speed is definitely not a factor for me. I'm wondering, though, if it's possible to implement "backup" w...

many1 no longer works with Parsec 3.x

After updating to Parsec 3.1 from 2.x, code using many1, such as word = many1 letter fails with No instance for (Stream s m Char) arising from a use of `letter' I found a mailing list post claiming that adding {-#LANGUAGE NoMonomorphismRestriction #-} to the top of the source file would solve the problem, but it did not. ...

Custom whiteSpace using Haskell Parsec

I would like to use Parsec's makeTokenParser to build my parser, but I want to use my own definition of whiteSpace. Doing the following replaces whiteSpace with my definition, but all the lexeme parsers still use the old definition (e.g. P.identifier lexer will use the old whiteSpace). ... lexer :: P.TokenParser () lexer = l { P.w...

Parsec Haskell Lists

I'm using Text.ParserCombinators.Parsec and Text.XHtml to parse an input and get a HTML output. If my input is: * First item, First level ** First item, Second level ** Second item, Second level * Second item, First level My output should be: <ul><li>First item, First level <ul><li>First item, Second level </li><li>...

Haskell Parse Paragraph and em element with Parsec

I'm using Text.ParserCombinators.Parsec and Text.XHtml to parse an input like this: this is the beginning of the paragraph --this is an emphasized text-- and this is the end\n And my output should be: <p>this is the beginning of the paragraph <em>this is an emphasized text</em> and this is the end\n</p> This code parses and returns a...

Haskell - Parsec Parsing <p> element

I'm using Text.ParserCombinators.Parsec and Text.XHtml to parse an input like this: This is the first paragraph example\n with two lines\n \n And this is the second paragraph\n And my output should be: <p>This is the first paragraph example\n with two lines\n</p> <p>And this is the second paragraph\n</p> I defined: line= d...

Haskell Parsec items numeration

I'm using Text.ParserCombinators.Parsec and Text.XHtml to parse an input like this: - First type A\n -- First type B\n - Second type A\n -- First type B\n --Second type B\n And my output should be: <h1>1 First type A\n</h1> <h2>1.1 First type B\n</h2> <h1>2 Second type A\n</h2> <h2>2.1 First type B\n</h2> <h2>2.2 Second ty...

Parsing Indentation-based syntaxes in Haskell's Parsec

I'm trying to parse an indentation-based language (think Python, Haskell itself, Boo, YAML) in Haskell using Parsec. I've seen the IndentParser library, and it looks like it's the perfect match, but what I can't figure out is how to make my TokenParser into an indentation parser. Here's the code I have so far: import qualified Text.Pars...

Haskell: Lifting a reads function to a parsec parser

As part of the 4th exercise here I would like to use a reads type function such as readHex with a parsec Parser. To do this I have written a function: liftReadsToParse :: Parser String -> (String -> [(a, String)]) -> Parser a liftReadsToParse p f = p >>= \s -> if null (f s) then fail "No parse" else (return . fst . head ) (f s) Which...