From c75f5e75d567181ab0267cf4224a3cea59adc53f Mon Sep 17 00:00:00 2001 From: ianbicking Date: Tue, 23 Mar 2004 23:21:11 +0000 Subject: Reader parses docstrings (according to __docformat__) and produces full output. The reader should thus be "done". Run readers/python/__init__.py with a filename argument to get output in the DOM format. A transformer will be necessary to translate this into the standard docutils DOM. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1881 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/readers/python/moduleparser.py | 115 +++++++++++++++++++------------- 1 file changed, 70 insertions(+), 45 deletions(-) (limited to 'docutils/readers/python/moduleparser.py') diff --git a/docutils/readers/python/moduleparser.py b/docutils/readers/python/moduleparser.py index c95d997c8..7f965e6e2 100644 --- a/docutils/readers/python/moduleparser.py +++ b/docutils/readers/python/moduleparser.py @@ -7,11 +7,10 @@ """ Parser for Python modules. -The `parse_module()` function takes a module's text and file name, runs it -through the module parser (using compiler.py and tokenize.py) and produces a -"module documentation tree": a high-level AST full of nodes that are -interesting from an auto-documentation standpoint. For example, given this -module (x.py):: +The `parse_module()` function takes a module's text and file name, +runs it through the module parser (using compiler.py and tokenize.py) +and produces a parse tree of the source code, using the nodes as found +in pynodes.py. For example, given this module (x.py):: # comment @@ -50,69 +49,95 @@ module (x.py):: The module parser will produce this module documentation tree:: - - - comment - + + Docstring - + Additional docstring - - + + + __docformat__ + 'reStructuredText' - - + + + a + 1 - + Attribute docstring - - + + + C + + Super + C's docstring - - + + + class_attribute + 1 - + class_attribute's docstring - - + + + __init__ + __init__'s docstring - - - - + + + + self + + + text + None - - + + + self.instance_attribute + (text * 7 + ' whaddyaknow') - + instance_attribute's docstring - - + + + f + f's docstring - - - + + + + x + # parameter x - - + + + y + a * 5 - + # parameter y - - + + + args + # parameter args - - + + + f.function_attribute + 1 - + f.function_attribute's docstring (Comments are not implemented yet.) compiler.parse() provides most of what's needed for this doctree, and -"tokenize" can be used to get the rest. We can determine the line number from -the compiler.parse() AST, and the TokenParser.rhs(lineno) method provides the -rest. +"tokenize" can be used to get the rest. We can determine the line +number from the compiler.parse() AST, and the TokenParser.rhs(lineno) +method provides the rest. The Docutils Python reader component will transform this module doctree into a Python-specific Docutils doctree, and then a `stylist transform`_ will -- cgit v1.2.1