[Epydoc-commits] SF.net SVN: epydoc: [1511] trunk/epydoc/src/epydoc/docparser.py
Brought to you by:
edloper
From: <dva...@us...> - 2007-02-16 02:08:53
|
Revision: 1511 http://svn.sourceforge.net/epydoc/?rev=1511&view=rev Author: dvarrazzo Date: 2007-02-15 18:08:51 -0800 (Thu, 15 Feb 2007) Log Message: ----------- - The parser detects te trick:: if __name__ == "__main__": and skips the block (or else testing stuff gets parsed). Modified Paths: -------------- trunk/epydoc/src/epydoc/docparser.py Modified: trunk/epydoc/src/epydoc/docparser.py =================================================================== --- trunk/epydoc/src/epydoc/docparser.py 2007-02-16 01:28:57 UTC (rev 1510) +++ trunk/epydoc/src/epydoc/docparser.py 2007-02-16 02:08:51 UTC (rev 1511) @@ -683,6 +683,15 @@ else: container.group_specs.append( (group_name, [var_name]) ) +def script_guard(line): + """Detect the idiomatic trick C{if __name__ == "__main__":}""" + return (len(line) == 5 + and line[1][1] == '__name__' # this is the most selective + and line[0][1] == 'if' + and line[2][1] == '==' + and line[4][1] == ':' + and line[3][1][1:-1] == '__main__') + #///////////////////////////////////////////////////////////////// #{ Shallow parser #///////////////////////////////////////////////////////////////// @@ -787,7 +796,7 @@ docs_extracted_by='parser') set_variable(parent, var_doc) - if ((keyword == 'if' and PARSE_IF_BLOCKS) or + if ((keyword == 'if' and PARSE_IF_BLOCKS and not script_guard(line)) or (keyword == 'elif' and PARSE_ELSE_BLOCKS) or (keyword == 'else' and PARSE_ELSE_BLOCKS) or (keyword == 'while' and PARSE_WHILE_BLOCKS) or This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |