Changeset 935
- Timestamp:
- Jun 15, 2012 1:06:35 PM (11 years ago)
- Location:
- specdomain/src/specdomain
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
specdomain/src/specdomain/sphinxcontrib/specdomain.py
r930 r935 28 28 29 29 30 match_all = '.*' 31 non_greedy_filler = match_all+'?' 32 double_quote_string_match = '("'+non_greedy_filler+'")' 33 word_match = '((?:[a-z_][\w]*))' 34 cdef_match = '(cdef)' 35 36 30 37 spec_macro_sig_re = re.compile( 31 38 r'''^ ([a-zA-Z_]\w*) # macro name 32 39 ''', re.VERBOSE) 40 41 spec_func_sig_re = re.compile(word_match+'\(' 42 + '('+match_all+')' 43 + '\)', 44 re.IGNORECASE|re.DOTALL) 45 46 spec_cdef_name_sig_re = re.compile(double_quote_string_match, re.IGNORECASE|re.DOTALL) 33 47 34 48 … … 49 63 def _get_index_text(self, name): 50 64 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', 54 68 } 55 69 if self.objtype in macro_types: … … 64 78 # def macro_name(arg1, arg2) 65 79 # 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) 68 82 if m is None: 69 83 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() 75 85 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: 76 97 signode += addnodes.desc_name(name, name) 77 if len(arglist) > 1:78 args = sig.lstrip(name).strip()79 98 if len(args) > 0: 80 99 signode += addnodes.desc_addname(args, args) -
specdomain/src/specdomain/test/starter.py
r934 r935 19 19 :param str parent: path to *build* subdirectory (either ``build`` or ``_build``) 20 20 ''' 21 if os.path.exists(parent ):21 if os.path.exists(parent+'/doctrees'): 22 22 garbage_list = [ 23 23 parent+'/doctrees/environment.pickle', -
specdomain/src/specdomain/test/test_doc.rst
r930 r935 26 26 This is a standard SPEC macro definition. 27 27 28 .. spec:def:: def_function(arguments) 29 30 :param str arguments: named argument(s) to this function 31 28 32 .. spec:rdef:: rdef_macro content 29 33 30 34 This is a SPEC macro definition with symbols that are evaluated only at run-time. 31 35 32 .. spec:cdef:: cdef( macro_name, [content, groupname, [flags]])36 .. spec:cdef:: cdef("cdef_macro", "content", "cdef_part", flags) 33 37 34 :param str macro_name: one-word name (quoted string) for this macro chain38 :param str cdef_macro: one-word name (quoted string) for this macro chain 35 39 :param str content: SPEC code to be inserted (typically a single macro) 36 :param str groupname: name of organizational group40 :param str cdef_part: name for this part of the chained macro 37 41 :param str flags: see the manual 38 42 … … 69 73 70 74 * macro definition: :spec:def:`def_macro` 75 * function definition: :spec:def:`def_function(arguments)` 71 76 * 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)` 73 78 74 79 SPEC Variables -
specdomain/src/specdomain/test/tester.py
r934 r935 7 7 8 8 # http://regexpal.com/ 9 # http://www.txt2re.com/index-python.php39 # http://www.txt2re.com/index-python.php3 10 10 11 11 def tester(test_cases, regexp): … … 120 120 func_start_re = re.compile(word_match+'\(', 121 121 re.IGNORECASE|re.DOTALL) 122 func_match_re = re.compile(word_match+'\(' 123 + '('+match_all+')' 124 + '\)', 125 re.IGNORECASE|re.DOTALL) 122 126 # 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 128 tester(test_cases, func_match_re) 129 130 131 ################################################################################## 132 133 txt='\'"macro_name", "content", "groupname", flags\'' 134 135 uninteresting_csv = non_greedy_filler+',' 136 csv_match = '(' + non_greedy_filler + '),' 137 138 re_str=non_greedy_filler # Non-greedy match on filler 139 re_str += double_quote_string # Double Quote String 1 140 re_str += non_greedy_filler # Non-greedy match on filler 141 re_str += uninteresting_csv # Uninteresting: csv 142 re_str += non_greedy_filler # Non-greedy match on filler 143 re_str += csv_match # Command Seperated Values 1 144 re_str += non_greedy_filler # Non-greedy match on filler 145 re_str += uninteresting_csv # Uninteresting: csv 146 re_str += non_greedy_filler # Non-greedy match on filler 147 re_str += csv_match # Command Seperated Values 2 148 149 re_str = "(.*)" 150 151 rg = re.compile(re_str, re.IGNORECASE|re.DOTALL) 152 153 test_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 ''' 162 print re_str 163 tester(test_cases, rg)
Note: See TracChangeset
for help on using the changeset viewer.