|
From: David G. <go...@py...> - 2002-12-19 01:16:13
|
The first part of the Docutils Python Source Reader component is in a usable form: <http://docutils.sf.net/docutils/readers/python/moduleparser.py>. It takes a module's text (a string) and converts it into a documentation-oriented tree. Assignments/attributes, functions, classes, and methods are all converted. Arbitrarily complex right-hand sides of assignments (including default parameter values) are supported by parsing tokens from tokenize.py. Comments are not handled yet, and namespaces are not computed. There's a list of open issues at the end of the module docstring. I've also added a "showdoc" script to test/test_readers/test_python which processes input from the test_parser.py module, or stdin, depending on how it's called. Please play with these; any input is welcome. Here's a sample. Given this module as input:: # comment """Docstring""" """Additional docstring""" __docformat__ = 'reStructuredText' a = 1 """Attribute docstring""" class C(Super): """C's docstring""" class_attribute = 1 """class_attribute's docstring""" def __init__(self, text=None): """__init__'s docstring""" self.instance_attribute = (text * 7 + ' whaddyaknow') """instance_attribute's docstring""" def f(x, # parameter x y=a*5, # parameter y *args): # parameter args """f's docstring""" return [x + item for item in args] f.function_attribute = 1 """f.function_attribute's docstring""" Here's the output tree, with objects converted to the pseudo-XML form I'm fond of:: <Module filename="<stdin>"> <Docstring> Docstring <Docstring lineno="5"> Additional docstring <Attribute lineno="7" name="__docformat__"> <Expression lineno="7"> 'reStructuredText' <Attribute lineno="9" name="a"> <Expression lineno="9"> 1 <Docstring lineno="10"> Attribute docstring <Class bases="Super" lineno="12" name="C"> <Docstring lineno="12"> C's docstring <Attribute lineno="16" name="class_attribute"> <Expression lineno="16"> 1 <Docstring lineno="17"> class_attribute's docstring <Method lineno="19" name="__init__"> <Docstring lineno="19"> __init__'s docstring <ParameterList lineno="19"> <Parameter lineno="19" name="self"> <Parameter lineno="19" name="text"> <Default lineno="19"> None <Attribute lineno="22" name="self.instance_attribute"> <Expression lineno="22"> (text * 7 + ' whaddyaknow') <Docstring lineno="24"> instance_attribute's docstring <Function lineno="27" name="f"> <Docstring lineno="27"> f's docstring <ParameterList lineno="27"> <Parameter lineno="27" name="x"> <Parameter lineno="27" name="y"> <Default lineno="27"> a * 5 <ExcessPositionalArguments lineno="27" name="args"> <Attribute lineno="33" name="f.function_attribute"> <Expression lineno="33"> 1 <Docstring lineno="34"> f.function_attribute's docstring -- David Goodger <go...@py...> Open-source projects: - Python Docutils: http://docutils.sourceforge.net/ (includes reStructuredText: http://docutils.sf.net/rst.html) - The Go Tools Project: http://gotools.sourceforge.net/ |
|
From: Richard J. <rj...@ek...> - 2002-12-19 03:00:50
|
On Thu, 19 Dec 2002 12:17 pm, David Goodger wrote: > I've also added a "showdoc" script to test/test_readers/test_python > which processes input from the test_parser.py module, or stdin, > depending on how it's called. Please play with these; any input is > welcome. I've found a module it breaks on ;) I'm looking into why right now... Richard |
|
From: Richard J. <rj...@ek...> - 2002-12-19 03:11:18
|
On Thu, 19 Dec 2002 1:59 pm, Richard Jones wrote:
> On Thu, 19 Dec 2002 12:17 pm, David Goodger wrote:
> > I've also added a "showdoc" script to test/test_readers/test_python
> > which processes input from the test_parser.py module, or stdin,
> > depending on how it's called. Please play with these; any input is
> > welcome.
>
> I've found a module it breaks on ;)
>
> I'm looking into why right now...
This breaks, still looking into it:
class foo:
def __init__(self):
x = self.frozz(a="a", b="b")
[there's a problem with trying to pop the closing bracket from the stack, the
stack is already empty]
Richard
|
|
From: Richard J. <rj...@ek...> - 2002-12-19 03:38:14
|
On Thu, 19 Dec 2002 2:10 pm, Richard Jones wrote:
> On Thu, 19 Dec 2002 1:59 pm, Richard Jones wrote:
> > On Thu, 19 Dec 2002 12:17 pm, David Goodger wrote:
> > > I've also added a "showdoc" script to test/test_readers/test_python
> > > which processes input from the test_parser.py module, or stdin,
> > > depending on how it's called. Please play with these; any input is
> > > welcome.
> >
> > I've found a module it breaks on ;)
> >
> > I'm looking into why right now...
>
> This breaks, still looking into it:
>
>
> class foo:
> def __init__(self):
> x = self.frozz(a="a", b="b")
I've checked in the simplest breaking expression:
class C:
def __init__(self):
local = foo(a = 1)
which I believe should evaluate to:
<Module filename="test data">
<Class lineno="1" name="C">
<Method lineno="2" name="__init__">
<ParameterList lineno="2">
<Parameter lineno="2" name="self">
<Attribute lineno="3" name="local">
<Expression lineno="3">
foo(a = 1)
But at the moment the rhs evaluation gets mighty confused when it hits that
second '='.
Richard
|
|
From: David G. <go...@py...> - 2002-12-19 04:43:17
|
Richard Jones wrote: >>> I've found a module it breaks on ;) >>> >>> I'm looking into why right now... > > But at the moment the rhs evaluation gets mighty confused when it hits that > second '='. Some naive logic in the TokenParser. Fixed now. Thanks for making this bug shallow! -- David Goodger go...@py... |
|
From: Richard J. <rj...@ek...> - 2002-12-19 05:06:10
|
On Thu, 19 Dec 2002 3:44 pm, David Goodger wrote: > Richard Jones wrote: > >>> I've found a module it breaks on ;) > >>> > >>> I'm looking into why right now... > > > > But at the moment the rhs evaluation gets mighty confused when it hits > > that second '='. > > Some naive logic in the TokenParser. Fixed now. Yep, all better now :) The structure output looks mighty promising - great job! Richard |