Changeset 935


Ignore:
Timestamp:
Jun 15, 2012 1:06:35 PM (11 years ago)
Author:
jemian
Message:

refs #8, now handles cdef (still needs to parse additional arguments properly), Index entries are much improved, now gathers definitions together in index

Location:
specdomain/src/specdomain
Files:
1 added
4 edited

Legend:

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

    r930 r935  
    2828
    2929
     30match_all                   = '.*'
     31non_greedy_filler           = match_all+'?'
     32double_quote_string_match   = '("'+non_greedy_filler+'")'
     33word_match                  = '((?:[a-z_][\w]*))'
     34cdef_match                  = '(cdef)'
     35
     36
    3037spec_macro_sig_re = re.compile(
    3138    r'''^ ([a-zA-Z_]\w*)         # macro name
    3239          ''', re.VERBOSE)
     40
     41spec_func_sig_re = re.compile(word_match+'\('
     42                      + '('+match_all+')'
     43                      + '\)',
     44                      re.IGNORECASE|re.DOTALL)
     45
     46spec_cdef_name_sig_re = re.compile(double_quote_string_match, re.IGNORECASE|re.DOTALL)
    3347
    3448
     
    4963    def _get_index_text(self, name):
    5064        macro_types = {
    51             'def':  '%s (SPEC macro)',
    52             'rdef': '%s (SPEC run-time macro)',
    53             'cdef': '%s (SPEC chained macro)',
     65            'def':  'SPEC macro definition; %s',
     66            'rdef': 'SPEC run-time macro definition; %s',
     67            'cdef': 'SPEC chained macro definition; %s',
    5468        }
    5569        if self.objtype in macro_types:
     
    6478        #     def macro_name(arg1, arg2)
    6579        #     rdef macro_name
    66         #     cdef(macro_name, content, groupname, flags)
    67         m = spec_macro_sig_re.match(sig)
     80        #     cdef("macro_name", "content", "groupname", flags)
     81        m = spec_func_sig_re.match(sig) or spec_macro_sig_re.match(sig)
    6882        if m is None:
    6983            raise ValueError
    70         arglist = sig.strip().split()
    71         if len(arglist) == 0:
    72             raise ValueError
    73         if sig.startswith('cdef'):
    74             special = sig.lstrip('cdef')
     84        arglist = m.groups()
    7585        name = arglist[0]
     86        args = []
     87        if len(arglist) > 1:
     88            args = arglist[1:]
     89            if name == 'cdef':
     90                # TODO: need to match complete arg list
     91                # several different signatures are possible (see cdef-examples.mac)
     92                # for now, just get the macro name and ignore the arg list
     93                m = spec_cdef_name_sig_re.match(args[0])
     94                arglist = m.groups()
     95                name = arglist[0].strip('"')
     96                args = []                       # FIXME:
    7697        signode += addnodes.desc_name(name, name)
    77         if len(arglist) > 1:
    78             args = sig.lstrip(name).strip()
    7998        if len(args) > 0:
    8099            signode += addnodes.desc_addname(args, args)
  • specdomain/src/specdomain/test/starter.py

    r934 r935  
    1919    :param str parent: path to *build* subdirectory (either ``build`` or ``_build``)
    2020    '''
    21     if os.path.exists(parent):
     21    if os.path.exists(parent+'/doctrees'):
    2222        garbage_list = [
    2323            parent+'/doctrees/environment.pickle',
  • specdomain/src/specdomain/test/test_doc.rst

    r930 r935  
    2626   This is a standard SPEC macro definition.
    2727
     28.. spec:def:: def_function(arguments)
     29
     30   :param str arguments: named argument(s) to this function
     31
    2832.. spec:rdef:: rdef_macro content
    2933
    3034   This is a SPEC macro definition with symbols that are evaluated only at run-time.
    3135
    32 .. spec:cdef:: cdef(macro_name, [content, groupname, [flags]])
     36.. spec:cdef:: cdef("cdef_macro", "content", "cdef_part", flags)
    3337
    34    :param str macro_name: one-word name (quoted string) for this macro chain
     38   :param str cdef_macro: one-word name (quoted string) for this macro chain
    3539   :param str content: SPEC code to be inserted (typically a single macro)
    36    :param str groupname: name of organizational group
     40   :param str cdef_part: name for this part of the chained macro
    3741   :param str flags: see the manual
    3842
     
    6973
    7074* macro definition: :spec:def:`def_macro`
     75* function definition: :spec:def:`def_function(arguments)`
    7176* runtime-defined macro definition: :spec:rdef:`rdef_macro`
    72 * chained macro definition: :spec:cdef:`cdef(macro_name, content, groupname, flags)`
     77* chained macro definition: :spec:cdef:`cdef("cdef_macro", "content", "cdef_part", flags)`
    7378
    7479SPEC Variables
  • specdomain/src/specdomain/test/tester.py

    r934 r935  
    77
    88#  http://regexpal.com/
    9 #http://www.txt2re.com/index-python.php3
     9#  http://www.txt2re.com/index-python.php3
    1010
    1111def tester(test_cases, regexp):
     
    120120func_start_re = re.compile(word_match+'\(',
    121121                      re.IGNORECASE|re.DOTALL)
     122func_match_re = re.compile(word_match+'\('
     123                      + '('+match_all+')'
     124                      + '\)',
     125                      re.IGNORECASE|re.DOTALL)
    122126# cdef1_re is most general for recognizing any of the different cdef signatures
    123 tester(test_cases, cdef1_re)
     127# func_match_re is most general for recognizing any of the different cdef signatures
     128tester(test_cases, func_match_re)
     129
     130
     131##################################################################################
     132
     133txt='\'"macro_name", "content", "groupname", flags\''
     134
     135uninteresting_csv = non_greedy_filler+','
     136csv_match = '(' + non_greedy_filler + '),'
     137
     138re_str=non_greedy_filler        # Non-greedy match on filler
     139re_str += double_quote_string   # Double Quote String 1
     140re_str += non_greedy_filler     # Non-greedy match on filler
     141re_str += uninteresting_csv     # Uninteresting: csv
     142re_str += non_greedy_filler     # Non-greedy match on filler
     143re_str += csv_match             # Command Seperated Values 1
     144re_str += non_greedy_filler     # Non-greedy match on filler
     145re_str += uninteresting_csv     # Uninteresting: csv
     146re_str += non_greedy_filler     # Non-greedy match on filler
     147re_str += csv_match             # Command Seperated Values 2
     148
     149re_str = "(.*)"
     150
     151rg = re.compile(re_str, re.IGNORECASE|re.DOTALL)
     152
     153test_cases = '''
     154'"macro_name", "commands", "partname", "delete"'
     155'"macro_name", "commands", "partname", flags'
     156'"cleanup_once", sprintf("dscan_cleanup $1 %s;", _c1), "dscan"'
     157'"macro_name", "commands", "partname"'
     158'"macro_name"'
     159'"geo_ub_default", "", "ub.mac"'
     160'"config_mac", "{PLOT_CNTRS_MAX = COUNTERS}", "PLOT_Y", 0x10'
     161'''
     162print re_str
     163tester(test_cases, rg)
Note: See TracChangeset for help on using the changeset viewer.