language-python-0.5.4: Parsing and pretty printing of Python code.

Copyright | (c) 2009 Bernie Pope
License | BSD-style
Maintainer | bjpop@csse.unimelb.edu.au
Stability | experimental
Portability | ghc
Safe Haskell | None
Language | Haskell98

Language.Python.Version3.Parser

Contents

- Parsing modules
- Parsing statements
- Parsing expressions

Description

A parser for Python version 3.x programs. Parsers are provided for modules, statements, and expressions. The parsers produce comment tokens in addition to the abstract syntax tree.

See:

- http://www.python.org/doc/3.1/reference/index.html for an overview of the language.
- http://www.python.org/doc/3.1/reference/grammar.html for the full grammar.
- http://www.python.org/doc/3.1/reference/toplevel_components.html for a description of the various Python top-levels, which correspond to the parsers provided here.

Synopsis

- parseModule :: String -> String -> Either ParseError (ModuleSpan, [Token])
- parseStmt :: String -> String -> Either ParseError ([StatementSpan], [Token])
- parseExpr :: String -> String -> Either ParseError (ExprSpan, [Token])

# Parsing modules

parseModule #

Arguments

:: String | The input stream (python module source code).
-> String | The name of the python source (filename or input device).
-> Either ParseError (ModuleSpan, [Token]) | An error or the abstract syntax tree (AST) of the python module and comment tokens.

Parse a whole Python source file. Return comments in addition to the parsed module.

# Parsing statements

parseStmt #

Arguments

:: String | The input stream (python statement source code).
-> String | The name of the python source (filename or input device).
-> Either ParseError ([StatementSpan], [Token]) | An error or maybe the abstract syntax tree (AST) of zero or more python statements, plus comments.

Parse one compound statement, or a sequence of simple statements. Generally used for interactive input, such as from the command line of an interpreter. Return comments in addition to the parsed statements.

# Parsing expressions

parseExpr #

Arguments

:: String | The input stream (python statement source code).
-> String | The name of the python source (filename or input device).
-> Either ParseError (ExprSpan, [Token]) | An error or maybe the abstract syntax tree (AST) of the python expression, plus comment tokens.

Parse an expression. Generally used as input for the 'eval' primitive. Return comments in addition to the parsed expression.