DESIGN 1.57 KB
Newer Older
1 2
Python Plugin Design:

Sven Brauch's avatar
Sven Brauch committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
This plugin consists of two parts: the parser, which is intended to create an
abstract syntax tree (AST) from a string of python code, and the DUChain Library,
which analyzes this AST semantically, extracting information about contexts, variable /
class / function declarations, and other stuff.

The parser
----------
... is not written by us. We're querying the python C API to extract an AST from a given
string of python code. For information about the parser API, see 
http://docs.python.org/c-api/veryhigh.html?highlight=pyparser_#PyParser_SimpleParseString
(for example). As this AST is based on PyObjects, relies on a large amount of macros for data
access, and is not based on classes, but on structs, we transform it to a more convenient form.
This is done in parser/astbuilder.cpp by the PythonAstTransformer class. It walks through a python
tree, and generates the corresponding plugin-tree objects (those which end with Ast, like StatementAst etc.).
This transformer is not written by hand, but is generated by the conversionGenerator.py script. This script
reads information on how the AST should be transformed from the parser/python26.sdef file.
It should be obvious from the large amount of examples what those rules look like.
20
This class returns a CodeAst, which is then passed back to the parse job, which then calls
Sven Brauch's avatar
Sven Brauch committed
21 22
the DUChain classes to analyze the tree. If an error occurs, parsing is aborted and the error is
reported to the user.
23 24 25

The DUChain Library
-------------------
Sven Brauch's avatar
Sven Brauch committed
26
See http://api.kde.org/4.x-api/kdevplatform-apidocs/language/html/duchain-design.html