monadic parser with Happy and Alex

Hi. I have completed a draft of a CSS lexer, using Alex. http://hg.mperillo.ath.cx/haskell/webtools/file/tip/src/CSS/Lexer.x The lexer use the posn wrapper. Now I'm starting to write the parser with Happy, however for the final product I would like to: 1) Be able to do I/O in the lexer, for stylesheets inclusion (@import rule) 2) be able to keep state in the parser (or lexer?), for character transcoding (@charset rule) This should be possible with Happy (and there are some example), however I don't find examples that make use of a lexer written with Alex. Should I write a lexer using only the Alex basic interface (without wrappers)? Thanks Manlio Perillo

On Sat, 2008-10-04 at 17:05 +0200, Manlio Perillo wrote:
Hi.
I have completed a draft of a CSS lexer, using Alex. http://hg.mperillo.ath.cx/haskell/webtools/file/tip/src/CSS/Lexer.x
The lexer use the posn wrapper.
Now I'm starting to write the parser with Happy, however for the final product I would like to: 1) Be able to do I/O in the lexer, for stylesheets inclusion (@import rule) 2) be able to keep state in the parser (or lexer?), for character transcoding (@charset rule)
This should be possible with Happy (and there are some example), however I don't find examples that make use of a lexer written with Alex.
See c2hs or Language.C it uses a monadic lexer. Duncan

Duncan Coutts ha scritto:
[...]
Now I'm starting to write the parser with Happy, however for the final product I would like to: 1) Be able to do I/O in the lexer, for stylesheets inclusion (@import rule) 2) be able to keep state in the parser (or lexer?), for character transcoding (@charset rule)
This should be possible with Happy (and there are some example), however I don't find examples that make use of a lexer written with Alex.
See c2hs or Language.C it uses a monadic lexer.
Thanks. I'm also looking at HJS (unfortunately new versions use Parsec instead of Alex + Happy).
Duncan
Manlio

On Sun, 05 Oct 2008 04:05:51 Manlio Perillo wrote:
Hi.
I have completed a draft of a CSS lexer, using Alex. http://hg.mperillo.ath.cx/haskell/webtools/file/tip/src/CSS/Lexer.x
The lexer use the posn wrapper.
Now I'm starting to write the parser with Happy, however for the final product I would like to: 1) Be able to do I/O in the lexer, for stylesheets inclusion (@import rule) 2) be able to keep state in the parser (or lexer?), for character transcoding (@charset rule)
This should be possible with Happy (and there are some example), however I don't find examples that make use of a lexer written with Alex.
Should I write a lexer using only the Alex basic interface (without wrappers)?
Thanks Manlio Perillo _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Hi Manlio, You may be better off separating the parsing from the import process. You would first parse it in to internal data structures (including an option for import) then go through that and replace import statements with the parsed content of those files. Producing a list which is then consumed by an IO procedure is almost exactly equivalent to threading IO through the entire parser and is a lot tidier, more flexible and should be easier to maintain. Cheers, Tim

Timothy Goddard ha scritto:
On Sun, 05 Oct 2008 04:05:51 Manlio Perillo wrote:
Hi.
I have completed a draft of a CSS lexer, using Alex. http://hg.mperillo.ath.cx/haskell/webtools/file/tip/src/CSS/Lexer.x
The lexer use the posn wrapper.
Now I'm starting to write the parser with Happy, however for the final product I would like to: 1) Be able to do I/O in the lexer, for stylesheets inclusion (@import rule) 2) be able to keep state in the parser (or lexer?), for character transcoding (@charset rule)
This should be possible with Happy (and there are some example), however I don't find examples that make use of a lexer written with Alex.
Should I write a lexer using only the Alex basic interface (without wrappers)?
Thanks Manlio Perillo _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Hi Manlio,
You may be better off separating the parsing from the import process. You would first parse it in to internal data structures (including an option for import) then go through that and replace import statements with the parsed content of those files.
Thanks, this seems the best solution.
Producing a list which is then consumed by an IO procedure is almost exactly equivalent to threading IO through the entire parser and is a lot tidier, more flexible and should be easier to maintain.
Regards Manlio
participants (3)
-
Duncan Coutts
-
Manlio Perillo
-
Timothy Goddard