Changeset 930


Ignore:
Timestamp:
Jun 14, 2012 1:12:01 PM (11 years ago)
Author:
jemian
Message:

refs #8, progress on adding directives to the index

Location:
specdomain/src
Files:
3 edited

Legend:

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

    r920 r930  
    3232        name, args, last = m.groups()
    3333        print name, args.strip().split()
     34
     35spec_macro_sig_re = re.compile(
     36    r'''^ ([a-zA-Z_]\w*)         # macro name
     37          ''', re.VERBOSE)
     38
     39sig = u'cdef(macro_name, content, groupname, flags)'
     40m = spec_macro_sig_re.match(sig)
     41print m.groups()
     42print args
     43
  • specdomain/src/specdomain/sphinxcontrib/specdomain.py

    r929 r930  
    2828
    2929
     30spec_macro_sig_re = re.compile(
     31    r'''^ ([a-zA-Z_]\w*)         # macro name
     32          ''', re.VERBOSE)
     33
     34
    3035class SpecObject(ObjectDescription):
    3136    """
     
    3338    """
    3439
     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
    3560    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]
    4176        signode += addnodes.desc_name(name, name)
     77        if len(arglist) > 1:
     78            args = sig.lstrip(name).strip()
    4279        if len(args) > 0:
    4380            signode += addnodes.desc_addname(args, args)
    4481        return name
    4582
    46     def _get_index_text(self, name):    # TODO: needs to be checked
    47         if self.objtype == 'def':
    48             return _('%s (SPEC macro)') % name
    49         elif self.objtype == 'rdef':
    50             return _('%s (SPEC macro)') % name
    51         elif self.objtype == 'cdef':
    52             return _('%s (SPEC global)') % name
    53         else:
    54             return ''
    55 
    5683
    5784class 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
    5889
    5990    def process_link(self, env, refnode, has_explicit_title, title, target):
     
    72103
    73104    def result_nodes(self, document, env, node, is_ref):
     105        # this code adds index entries for each role instance
    74106        if not is_ref:
    75107            return [node], []
     
    88120class SpecDomain(Domain):
    89121    """SPEC language domain."""
     122   
    90123    name = 'spec'
    91124    label = 'SPEC, http://www.certif.com'
  • specdomain/src/specdomain/test/test_doc.rst

    r929 r930  
    2020^^^^^^^^^^^
    2121
    22 .. spec:def:: no_args_macro
     22.. spec:def:: def_macro content
    2323
    24 .. spec:def:: def_macro arg1 arg2 arg3
     24   :param str arg: list of arguments is optional
    2525
    26    :param arg1: anything
    27    :type  arg1: str
    28    :param arg2: another thing
     26   This is a standard SPEC macro definition.
    2927
    3028.. spec:rdef:: rdef_macro content
    3129
    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.
    3431
    35 .. spec:cdef:: cdef_macro(identifier, content, placement)
     32.. spec:cdef:: cdef(macro_name, [content, groupname, [flags]])
    3633
    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
    4338
    4439SPEC Variables
     
    6762
    6863A *role* refers to a *directive* (makes a link to a *directive* defined elsewhere).
    69 Each of these items should produce a valid link.
     64Each of these items should produce a valid link.  Additionally, every call to a
     65*role* should produce an index entry.
    7066
    7167SPEC Macros
     
    7470* macro definition: :spec:def:`def_macro`
    7571* 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)`
    7773
    7874SPEC Variables
Note: See TracChangeset for help on using the changeset viewer.