Package pyplusplus :: Package decl_wrappers :: Module doc_extractor

# Source Code for Module pyplusplus.decl_wrappers.doc_extractor

     1  # Copyright 2004-2008 Roman Yakovenko.
     2  # Distributed under the Boost Software License, Version 1.0. (See
     3  # accompanying file LICENSE_1_0.txt or copy at
     4  # http://www.boost.org/LICENSE_1_0.txt)
     5
     6  """defines documentation extractor class interface"""
     7
     8  import re
     9
    10 -class doc_extractor_i(object):
    11      """defines documentation extractor interface"""
    12
    13      __escape_re = re.compile (r'((\\x[a-f0-9][a-f0-9])|(\\*"))', re.I)
    14
    15 -    def __init__( self, encoding='ascii' ):
    16          object.__init__( self )
    17          self.encoding = encoding
    18
    19 -    def extract( self, decl ):
    20          """returns documentation text for the declaration
    21
    22          This function should be implemented in derived class.
    23
    24          Using decl.location.file_name and decl.location.line variables you can
    25          find out the location of declaration within source file
    26          """
    27          raise NotImplementedError()
    28
    29 -    def __call__( self, decl ):
    30          decl_doc = self.extract( decl )
    31          return self.escape_doc( decl_doc )
    32
    33      @staticmethod
    34 -    def escape_doc( doc ):
    35          """converts a text to be valid C++ string literals"""
    36          def replace_escape(m):
    37              g = m.group(1)
    38              if g.startswith ('\\x'):
    39                  return g + '""'
    40              elif g == '"':
    41                  return '\\"'
    42              else:
    43                  return g
    44          return '"%s"' % doc_extractor_i.__escape_re.sub( replace_escape, repr(doc)[1:-1] )
    45