Language-python provides a parser (and lexer) for Python written in Haskell. Currently it only supports version 3 of Python (the most recent version), but it will support version 2 in the future.

The parser is implemented using Happy, and the lexer is implemented using Alex.

Web page: http://projects.haskell.org/language-python/

Hackage: 
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/language-python

Darcs: darcs get http://code.haskell.org/language-python/

Example:
$ ghci
Prelude> :m Language.Python.Version3.Parser
Prelude Language.Python.Version3.Parser> parseModule "def inc(x): return x + 1\n" [] Right (Module [Fun {fun_name = Ident "inc", fun_args = [Param {param_name = Ident "x", param_annotation = Nothing, param_default = Nothing}], fun_result_annotation = Nothing, fun_body = [Return {return_expr = Just (BinaryOp {operator = Plus, left_op_arg = Var (Ident "x"), right_op_arg = Int 1})}]}])

Prelude Language.Python.Version3.Parser> :m Language.Python.Version3.Lexer Prelude Language.Python.Version3.Lexer> lexOneToken "def inc(x): return x + 1\n" [] Right (Def (Sloc {sloc_filename = "", sloc_row = 1, sloc_column = 1})," inc(x): return x + 1\n")

This is the first release of the package (version 0.1.1) and there is still much to be improved, in particular:
   - Unicode support is incomplete.
- Source locations are sub-optimal, and will eventually become source spans.
   - The pretty printer needs polish.
- The parser only supports version 3 of Python. Support for Version 2 is a major goal, and should be straightforward. - Only minimal performance tuning and correctness testing has been performed. Version 0.1.1 is not intended for production use.

Cheers,
Bernie.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to