Basic Parsec question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Basic Parsec question

Zachary Turner-2
Hi,

I downloaded the package lispparser to, well, parse lisp code.  I really
have absolutely no idea what I'm doing though.  I can look at the source of
the module and see that it's exporting a single data type called LispVal and
a single function called parseExpr, so somehow I should be able to pass an
arbitrary block of lisp code into this function and get back a LispVal.  But
for the life of me I can't figure out how.  I've looked at the documentation
but I get even more confused because it links me to the Parsec documentation
which is probably way over my head.  Basically I just want a simple
function:

parse :: String -> LispVal
parse expr = ???

presumably by making some use of the exported 'thing' (since I'm not really
sure how to interpret its type)

parseExpr :: Parser LispVal

Thanks for any help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090331/3f884cb0/attachment.htm
Reply | Threaded
Open this post in threaded view
|

Basic Parsec question

Antoine Latter-2
2009/3/31 Zachary Turner <[hidden email]>:

> Hi,
>
> I downloaded the package lispparser to, well, parse lisp code.? I really
> have absolutely no idea what I'm doing though.? I can look at the source of
> the module and see that it's exporting a single data type called LispVal and
> a single function called parseExpr, so somehow I should be able to pass an
> arbitrary block of lisp code into this function and get back a LispVal.? But
> for the life of me I can't figure out how.? I've looked at the documentation
> but I get even more confused because it links me to the Parsec documentation
> which is probably way over my head.? Basically I just want a simple
> function:
>
> parse :: String -> LispVal
> parse expr = ???
>
> presumably by making some use of the exported 'thing' (since I'm not really
> sure how to interpret its type)
>
> parseExpr :: Parser LispVal
>
> Thanks for any help
>

You should be able to use the function "parse" from the parsec package like so:

> parse parseExp "name of source for error reporting" "(some lisp expression")

The function "parse" returns a value of type (Either ParseError a),
where in this case the type-var 'a' wil be a LispVal.

Does that help?

Antoine
Reply | Threaded
Open this post in threaded view
|

Basic Parsec question

Zachary Turner-2
On Tue, Mar 31, 2009 at 11:34 PM, Antoine Latter <[hidden email]> wrote:

> You should be able to use the function "parse" from the parsec package like
> so:
>
> > parse parseExp "name of source for error reporting" "(some lisp
> expression")
>
> The function "parse" returns a value of type (Either ParseError a),
> where in this case the type-var 'a' wil be a LispVal.
>
> Does that help?
>

That was perfect, thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090401/215831d0/attachment.htm