integrating Happy & Alex monads

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

integrating Happy & Alex monads

Richard Cobbe
I'm working on a program in which I'd like to use Alex and Happy to parse
the input.  I've written the scanner, and it uses Alex's "monadUserState"
wrapper to track source location and various other things.  Now, the
problem is to integrate it with the parser.  As far as I can tell from
reading the Happy documentation, I need to use a monadic Parser in Happy as
well, but the manuals don't relaly provide a lot of information about how
to integrate the two.  And I haven't really been able to find many examples
of this either.  Lots of folks cite "the Haskell parser", although I'm not
sure which implementation that's referring to.  I did check out the GHC
source, and while it contains an Alex parser specification, it doesn't look
like anything actually *uses* this, preferring instead a handwritten
parser.

Could anyone point me to a discussion of how to integrate these two tools,
or examples of places where folks have done this before?

Thanks much,

Richard
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: integrating Happy & Alex monads

Bernie Pope-2
Hi Richard,

I used Alex and Happy in my library for parsing Python. Here's some links to the relevant parts of the code:


It has been a while since I wrote that code (2009), so I'm a bit hazy on the details, but hopefully you can find what you need in there.

Cheers,
Bernie.


On 27 December 2013 07:08, Richard Cobbe <[hidden email]> wrote:
I'm working on a program in which I'd like to use Alex and Happy to parse
the input.  I've written the scanner, and it uses Alex's "monadUserState"
wrapper to track source location and various other things.  Now, the
problem is to integrate it with the parser.  As far as I can tell from
reading the Happy documentation, I need to use a monadic Parser in Happy as
well, but the manuals don't relaly provide a lot of information about how
to integrate the two.  And I haven't really been able to find many examples
of this either.  Lots of folks cite "the Haskell parser", although I'm not
sure which implementation that's referring to.  I did check out the GHC
source, and while it contains an Alex parser specification, it doesn't look
like anything actually *uses* this, preferring instead a handwritten
parser.

Could anyone point me to a discussion of how to integrate these two tools,
or examples of places where folks have done this before?

Thanks much,

Richard
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: integrating Happy & Alex monads

Jason Dagit-3
In reply to this post by Richard Cobbe
I made this example specifically to help people with this problem (the problem being that the documentation is spotty here).

It's the expression parser from the happy documentation using the monad that alex can generate for you. It's the cleanest and simplest way (and simplest example) that I found to merge the two. I should really submit this as a documentation fix to happy.


Enjoy!
Jason


On Thu, Dec 26, 2013 at 12:08 PM, Richard Cobbe <[hidden email]> wrote:
I'm working on a program in which I'd like to use Alex and Happy to parse
the input.  I've written the scanner, and it uses Alex's "monadUserState"
wrapper to track source location and various other things.  Now, the
problem is to integrate it with the parser.  As far as I can tell from
reading the Happy documentation, I need to use a monadic Parser in Happy as
well, but the manuals don't relaly provide a lot of information about how
to integrate the two.  And I haven't really been able to find many examples
of this either.  Lots of folks cite "the Haskell parser", although I'm not
sure which implementation that's referring to.  I did check out the GHC
source, and while it contains an Alex parser specification, it doesn't look
like anything actually *uses* this, preferring instead a handwritten
parser.

Could anyone point me to a discussion of how to integrate these two tools,
or examples of places where folks have done this before?

Thanks much,

Richard
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: integrating Happy & Alex monads

Richard Cobbe
On Thu, Dec 26, 2013 at 10:05:12PM -0800, Jason Dagit wrote:
> I made this example specifically to help people with this problem (the
> problem being that the documentation is spotty here).
>
> It's the expression parser from the happy documentation using the monad
> that alex can generate for you. It's the cleanest and simplest way (and
> simplest example) that I found to merge the two. I should really submit
> this as a documentation fix to happy.
>
> https://github.com/dagit/happy-plus-alex

Oh, wonderful!  I've only had a chance to glance at this quickly, but it
looks like it's exactly what I'm looking for.  I'll definitely spend some
more time with this example in a day or so when I have more time.

Thanks a bunch -- this is extremely helpful!

Richard
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe