Changeset 941


Ignore:
Timestamp:
Jun 18, 2012 9:53:39 AM (10 years ago)
Author:
jemian
Message:

working on the SPEC parser (to also grab file line numbers), still can't get extended comments into regular rst document body, going into the signature node instead, refs #8

Location:
specdomain/src/specdomain
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • specdomain/src/specdomain/sphinxcontrib/specdomain.py

    r940 r941  
    1919from docutils.parsers.rst import directives             #@UnusedImport
    2020
    21 from sphinx import addnodes                             #@UnusedImport
    22 from sphinx.roles import XRefRole                       #@UnusedImport
     21from sphinx import addnodes
     22from sphinx.roles import XRefRole
    2323from sphinx.locale import l_, _                         #@UnusedImport
    24 from sphinx.directives import ObjectDescription         #@UnusedImport
     24from sphinx.directives import ObjectDescription
    2525from sphinx.domains import Domain, ObjType, Index       #@UnusedImport
    2626from sphinx.util.compat import Directive                #@UnusedImport
    27 from sphinx.util.nodes import make_refnode              #@UnusedImport
    28 from sphinx.util.docfields import Field, TypedField     #@UnusedImport
    29 
    30 
    31 match_all                   = '.*'
    32 non_greedy_filler           = match_all+'?'
    33 double_quote_string_match   = '("'+non_greedy_filler+'")'
    34 word_match                  = '((?:[a-z_]\w*))'
    35 cdef_match                  = '(cdef)'
    36 extended_comment_flag       = '\"\"\"'
     27from sphinx.util.nodes import make_refnode
     28from sphinx.util.docfields import Field, TypedField
     29from sphinx.util.docstrings import prepare_docstring    #@UnusedImport
     30
     31match_all                   = r'.*'
     32non_greedy_filler           = match_all + r'?'
     33double_quote_string_match   = r'("' + non_greedy_filler + r'")'
     34word_match                  = r'((?:[a-z_]\w*))'
     35cdef_match                  = r'(cdef)'
     36extended_comment_flag       = r'\"\"\"'
    3737
    3838
     
    4141                               ''', re.VERBOSE)
    4242
    43 spec_func_sig_re = re.compile(word_match+'\('
    44                       + '('+match_all+')'
    45                       + '\)',
     43spec_func_sig_re = re.compile(word_match + r'\('
     44                      + r'(' + match_all + r')'
     45                      + r'\)',
    4646                      re.IGNORECASE|re.DOTALL)
    4747
     
    5252spec_extended_comment_flag_sig_re = re.compile(extended_comment_flag,
    5353                                               re.IGNORECASE|re.DOTALL)
    54 spec_extended_comment_start_sig_re = re.compile('^'
     54spec_extended_comment_start_sig_re = re.compile(r'^'
    5555                                                + non_greedy_filler
    5656                                                + extended_comment_flag,
    5757                                                re.IGNORECASE|re.DOTALL)
    58 spec_extended_comment_block_sig_re = re.compile('^'
     58spec_extended_comment_block_sig_re = re.compile(r'^'
    5959                                                + non_greedy_filler
    6060                                                + extended_comment_flag
    61                                                 + '(' + non_greedy_filler + ')'
     61                                                + r'(' + non_greedy_filler + r')'
    6262                                                + extended_comment_flag
    6363                                                + non_greedy_filler
    64                                                 + '$',
     64                                                + r'$',
    6565                                                re.IGNORECASE|re.DOTALL|re.MULTILINE)
    6666
     
    198198        highlighted source code blocks.
    199199        '''
    200         results = self.parse_macro_file(sig)
    201         indent = ' '*4
    202         for item in results:
    203             # FIXME:  not desc_annotation but desc_content, but how to get it right?
    204             # see <sphinx>/directives/__init__.py for an example
    205             # It's a bit more complicated than this.
    206             signode += addnodes.desc_annotation('\n', '\n')
    207             for line in item.split('\n'):
    208                 signode += addnodes.desc_annotation(indent+line, indent+line)
     200        extended_comments_list = self.parse_macro_file(sig)
     201        for extended_comment in extended_comments_list:
     202            linenumber = -1                 # FIXME:
     203            #for line in prepare_docstring(extended_comment, ignore=1):
     204            #    self.result.append(self.indent + line, sig, linenumber)     # FIXME:
    209205        return sig
    210206   
     
    215211        :param str filename: name (with optional path) of SPEC macro file
    216212            (The path is relative to the ``.rst`` document.)
    217         :returns [str]: list of ReST-formatted extended comment blocks from SPEC macro file.
    218        
    219         [future] parse more stuff as planned
     213        :returns [str]: list of ReST-formatted extended comment blocks (docstrings) from SPEC macro file.
     214       
     215        [future] parse more stuff as planned, this is very simplistic for now
    220216        """
    221217        results = []
     
    224220       
    225221        buf = open(filename, 'r').read()
    226         # TODO: loop until no matches, chopping away the buffer after each match
    227         m = spec_extended_comment_block_sig_re.match(buf)
    228         if m is not None:
    229             rest = m.groups()
    230             if len(rest) == 1:
    231                 results.append(rest[0])
     222        #n = len(buf)
     223        for node in spec_extended_comment_block_sig_re.finditer(buf):
     224            #g = node.group()
     225            #gs = node.groups()
     226            #s = node.start()
     227            #e = node.end()
     228            #t = buf[s:e]
     229            results.append(node.groups())            # TODO: can we get line number also?
    232230        return results
    233231
  • specdomain/src/specdomain/test/starter.py

    r937 r941  
    1515def force_rebuild_all(parent = '_build'):
    1616    '''
    17     Delete the *doctrees* subdirectory.
     17    Delete the pickle file.
    1818   
    1919    :param str parent: path to *build* subdirectory (either ``build`` or ``_build``)
    2020    '''
    21     if os.path.exists(parent+'/doctrees'):
    22         garbage_list = [
    23             parent+'/doctrees/environment.pickle',
    24             #parent+'/doctrees/index.doctree',
    25             #parent+'/doctrees/test_doc.doctree',
    26         ]
    27         for item in garbage_list:
    28             if os.path.exists(item):
    29                 os.remove(item)
    30         #os.rmdir(parent+'/doctrees')
     21    pickle_file = parent+'/doctrees/environment.pickle'
     22    if os.path.exists(pickle_file):
     23        os.remove(pickle_file)
    3124
    3225
Note: See TracChangeset for help on using the changeset viewer.