Changeset 930
- Timestamp:
- Jun 14, 2012 1:12:01 PM (11 years ago)
- Location:
- specdomain/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
specdomain/src/round2/sphinxcontrib/tester.py
r920 r930 32 32 name, args, last = m.groups() 33 33 print name, args.strip().split() 34 35 spec_macro_sig_re = re.compile( 36 r'''^ ([a-zA-Z_]\w*) # macro name 37 ''', re.VERBOSE) 38 39 sig = u'cdef(macro_name, content, groupname, flags)' 40 m = spec_macro_sig_re.match(sig) 41 print m.groups() 42 print args 43 -
specdomain/src/specdomain/sphinxcontrib/specdomain.py
r929 r930 28 28 29 29 30 spec_macro_sig_re = re.compile( 31 r'''^ ([a-zA-Z_]\w*) # macro name 32 ''', re.VERBOSE) 33 34 30 35 class SpecObject(ObjectDescription): 31 36 """ … … 33 38 """ 34 39 40 def add_target_and_index(self, name, sig, signode): 41 targetname = '%s-%s' % (self.objtype, name) 42 signode['ids'].append(targetname) 43 self.state.document.note_explicit_target(signode) 44 indextext = self._get_index_text(name) 45 if indextext: 46 self.indexnode['entries'].append(('single', indextext, 47 targetname, '')) 48 49 def _get_index_text(self, name): 50 macro_types = { 51 'def': '%s (SPEC macro)', 52 'rdef': '%s (SPEC run-time macro)', 53 'cdef': '%s (SPEC chained macro)', 54 } 55 if self.objtype in macro_types: 56 return _(macro_types[self.objtype]) % name 57 else: 58 return '' 59 35 60 def handle_signature(self, sig, signode): 36 # TODO: must be able to match these 37 # def macro_name 38 # def macro_name() 39 # def macro_name(arg1, arg2) 40 name, args = sig.strip().split() 61 # Must be able to match these (without preceding def or rdef) 62 # def macro_name 63 # def macro_name() 64 # def macro_name(arg1, arg2) 65 # rdef macro_name 66 # cdef(macro_name, content, groupname, flags) 67 m = spec_macro_sig_re.match(sig) 68 if m is None: 69 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') 75 name = arglist[0] 41 76 signode += addnodes.desc_name(name, name) 77 if len(arglist) > 1: 78 args = sig.lstrip(name).strip() 42 79 if len(args) > 0: 43 80 signode += addnodes.desc_addname(args, args) 44 81 return name 45 82 46 def _get_index_text(self, name): # TODO: needs to be checked47 if self.objtype == 'def':48 return _('%s (SPEC macro)') % name49 elif self.objtype == 'rdef':50 return _('%s (SPEC macro)') % name51 elif self.objtype == 'cdef':52 return _('%s (SPEC global)') % name53 else:54 return ''55 56 83 57 84 class SpecXRefRole(XRefRole): # TODO: needs to be checked 85 """ """ 86 87 # TODO: output is not properly formatted yet 88 # TODO: output does not yet provide link to directive instance 58 89 59 90 def process_link(self, env, refnode, has_explicit_title, title, target): … … 72 103 73 104 def result_nodes(self, document, env, node, is_ref): 105 # this code adds index entries for each role instance 74 106 if not is_ref: 75 107 return [node], [] … … 88 120 class SpecDomain(Domain): 89 121 """SPEC language domain.""" 122 90 123 name = 'spec' 91 124 label = 'SPEC, http://www.certif.com' -
specdomain/src/specdomain/test/test_doc.rst
r929 r930 20 20 ^^^^^^^^^^^ 21 21 22 .. spec:def:: no_args_macro22 .. spec:def:: def_macro content 23 23 24 .. spec:def:: def_macro arg1 arg2 arg3 24 :param str arg: list of arguments is optional 25 25 26 :param arg1: anything 27 :type arg1: str 28 :param arg2: another thing 26 This is a standard SPEC macro definition. 29 27 30 28 .. spec:rdef:: rdef_macro content 31 29 32 :param content: SPEC code (single or multi-line but typically a single macro) 33 :type content: str 30 This is a SPEC macro definition with symbols that are evaluated only at run-time. 34 31 35 .. spec:cdef:: cdef _macro(identifier, content, placement)32 .. spec:cdef:: cdef(macro_name, [content, groupname, [flags]]) 36 33 37 :param identifier: one-word name for this macro chain 38 :type identifier: str 39 :param content: SPEC code to be inserted (typically a single macro) 40 :type content: str 41 :param placement: see the manual 42 :type placement: str 34 :param str macro_name: one-word name (quoted string) for this macro chain 35 :param str content: SPEC code to be inserted (typically a single macro) 36 :param str groupname: name of organizational group 37 :param str flags: see the manual 43 38 44 39 SPEC Variables … … 67 62 68 63 A *role* refers to a *directive* (makes a link to a *directive* defined elsewhere). 69 Each of these items should produce a valid link. 64 Each of these items should produce a valid link. Additionally, every call to a 65 *role* should produce an index entry. 70 66 71 67 SPEC Macros … … 74 70 * macro definition: :spec:def:`def_macro` 75 71 * runtime-defined macro definition: :spec:rdef:`rdef_macro` 76 * chained macro definition: :spec:cdef:`cdef _macro`72 * chained macro definition: :spec:cdef:`cdef(macro_name, content, groupname, flags)` 77 73 78 74 SPEC Variables
Note: See TracChangeset
for help on using the changeset viewer.