[pygccxml-commit] SF.net SVN: pygccxml: [515] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-09-04 06:18:05
|
Revision: 515 http://svn.sourceforge.net/pygccxml/?rev=515&view=rev Author: roman_yakovenko Date: 2006-09-03 23:17:49 -0700 (Sun, 03 Sep 2006) Log Message: ----------- adding documentation extractor interface to decl_wrappers package Modified Paths: -------------- pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py pyplusplus_dev/pyplusplus/module_builder/__init__.py pyplusplus_dev/unittests/algorithms_tester.py Added Paths: ----------- pyplusplus_dev/pyplusplus/decl_wrappers/doc_extractor.py Modified: pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2006-09-04 06:16:26 UTC (rev 514) +++ pyplusplus_dev/pyplusplus/decl_wrappers/__init__.py 2006-09-04 06:17:49 UTC (rev 515) @@ -89,48 +89,51 @@ from indexing_suite1 import indexing_suite1_t from indexing_suite2 import indexing_suite2_t +from doc_extractor import doc_extractor_i + class dwfactory_t( declarations.decl_factory_t ): """ declarations factory class """ def __init__(self): declarations.decl_factory_t.__init__(self) - + def create_member_function( self, *arguments, **keywords ): return member_function_t(*arguments, **keywords) - + def create_constructor( self, *arguments, **keywords ): return constructor_t(*arguments, **keywords) - + def create_destructor( self, *arguments, **keywords ): return destructor_t(*arguments, **keywords) - + def create_member_operator( self, *arguments, **keywords ): return member_operator_t(*arguments, **keywords) - + def create_casting_operator( self, *arguments, **keywords ): return casting_operator_t(*arguments, **keywords) - + def create_free_function( self, *arguments, **keywords ): return free_function_t(*arguments, **keywords) - + def create_free_operator( self, *arguments, **keywords ): return free_operator_t(*arguments, **keywords) def create_class_declaration(self, *arguments, **keywords ): return class_declaration_t(*arguments, **keywords) - + def create_class( self, *arguments, **keywords ): return class_t(*arguments, **keywords) - + def create_enumeration( self, *arguments, **keywords ): return enumeration_t(*arguments, **keywords) - + def create_namespace( self, *arguments, **keywords ): return namespace_t(*arguments, **keywords) - + def create_typedef( self, *arguments, **keywords ): return typedef_t(*arguments, **keywords) - + def create_variable( self, *arguments, **keywords ): return variable_t(*arguments, **keywords) + Added: pyplusplus_dev/pyplusplus/decl_wrappers/doc_extractor.py =================================================================== --- pyplusplus_dev/pyplusplus/decl_wrappers/doc_extractor.py (rev 0) +++ pyplusplus_dev/pyplusplus/decl_wrappers/doc_extractor.py 2006-09-04 06:17:49 UTC (rev 515) @@ -0,0 +1,45 @@ +# Copyright 2004 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +"""defines documentation extractor class interface""" + +import re + +class doc_extractor_i(object): + """defines documentation extractor interface""" + + __escape_re = re.compile (r'((\\x[a-f0-9][a-f0-9])|(\\*"))', re.I) + + def __init__( self, encoding='ascii' ): + object.__init__( self ) + self.encoding = encoding + + def extract( self, decl ): + """returns documentation text for the declaration + + This function should be implemented in derived class. + + Using decl.location.file_name and decl.location.line variables you can + find out the location of declaration within source file + """ + raise NotImplementedError() + + def __call__( self, decl ): + decl_doc = self.extract( decl ) + return self.escape_doc( decl_doc ) + + @staticmethod + def escape_doc( doc ): + """converts a text to be valid C++ string literals""" + def replace_escape(m): + g = m.group(1) + if g.startswith ('\\x'): + return g + '""' + elif g == '"': + return '\\"' + else: + return g + return '"%s"' % doc_extractor_i.__escape_re.sub( replace_escape, repr(doc)[1:-1] ) + Modified: pyplusplus_dev/pyplusplus/module_builder/__init__.py =================================================================== --- pyplusplus_dev/pyplusplus/module_builder/__init__.py 2006-09-04 06:16:26 UTC (rev 514) +++ pyplusplus_dev/pyplusplus/module_builder/__init__.py 2006-09-04 06:17:49 UTC (rev 515) @@ -8,7 +8,7 @@ functionality. L{module_builder_t} class is the main class. Please read it's documentation first. -Also take a look on tutorials. You can find them on Py++ +Also take a look on tutorials. You can find them on Py++ U{web site<http://www.language-binding.net>} """ @@ -45,6 +45,8 @@ from pyplusplus.decl_wrappers import print_declarations +from pyplusplus.decl_wrappers import doc_extractor_i + import call_policies from pygccxml import utils as __pygccxml_utils @@ -54,4 +56,4 @@ for l in __pygccxml_utils.loggers.all: l.setLevel( level ) for l in __pyplusplus_logging.loggers.all: - l.setLevel( level ) \ No newline at end of file + l.setLevel( level ) Modified: pyplusplus_dev/unittests/algorithms_tester.py =================================================================== --- pyplusplus_dev/unittests/algorithms_tester.py 2006-09-04 06:16:26 UTC (rev 514) +++ pyplusplus_dev/unittests/algorithms_tester.py 2006-09-04 06:17:49 UTC (rev 515) @@ -162,8 +162,14 @@ self.failUnless( [[1,2,3]] == split( seq, 3 ) ) self.failUnless( [[1,2,3]] == split( seq, 4 ) ) +class doc_extractor_tester_t( unittest.TestCase ): + def test( self ): + escaped_doc = module_builder.doc_extractor_i.escape_doc('Hello "Py++"') + self.failUnless( escaped_doc == '"Hello \\"Py++\\""' ) + def create_suite(): suite = unittest.TestSuite() + suite.addTest( unittest.makeSuite(doc_extractor_tester_t)) suite.addTest( unittest.makeSuite(class_organizer_tester_t)) suite.addTest( unittest.makeSuite(indent_tester_t)) suite.addTest( unittest.makeSuite(make_flatten_tester_t)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |