コード例 #1
0
ファイル: std.py プロジェクト: th0/test2
    def run(self):
        env = self.state.document.settings.env
        objects = env.domaindata['std']['objects']
        node = addnodes.productionlist()
        messages = []
        i = 0

        for rule in self.arguments[0].split('\n'):
            if i == 0 and ':' not in rule:
                # production group
                continue
            i += 1
            try:
                name, tokens = rule.split(':', 1)
            except ValueError:
                break
            subnode = addnodes.production()
            subnode['tokenname'] = name.strip()
            if subnode['tokenname']:
                idname = 'grammar-token-%s' % subnode['tokenname']
                if idname not in self.state.document.ids:
                    subnode['ids'].append(idname)
                self.state.document.note_implicit_target(subnode, subnode)
                objects['token', subnode['tokenname']] = env.docname, idname
            subnode.extend(token_xrefs(tokens))
            node.append(subnode)
        return [node] + messages
コード例 #2
0
ファイル: std.py プロジェクト: saimn/sphinx
    def run(self):
        # type: () -> List[nodes.Node]
        domain = cast(StandardDomain, self.env.get_domain('std'))
        node = addnodes.productionlist()  # type: nodes.Element
        i = 0

        for rule in self.arguments[0].split('\n'):
            if i == 0 and ':' not in rule:
                # production group
                continue
            i += 1
            try:
                name, tokens = rule.split(':', 1)
            except ValueError:
                break
            subnode = addnodes.production(rule)
            subnode['tokenname'] = name.strip()
            if subnode['tokenname']:
                idname = nodes.make_id('grammar-token-%s' %
                                       subnode['tokenname'])
                if idname not in self.state.document.ids:
                    subnode['ids'].append(idname)
                self.state.document.note_implicit_target(subnode, subnode)
                domain.add_object('token', subnode['tokenname'],
                                  self.env.docname, idname)
            subnode.extend(token_xrefs(tokens))
            node.append(subnode)
        return [node]
コード例 #3
0
ファイル: std.py プロジェクト: olivier-heurtier/sphinx
    def run(self):
        # type: () -> List[nodes.Node]
        domain = cast(StandardDomain, self.env.get_domain('std'))
        node = addnodes.productionlist()  # type: nodes.Element
        i = 0

        for rule in self.arguments[0].split('\n'):
            if i == 0 and ':' not in rule:
                # production group
                continue
            i += 1
            try:
                name, tokens = rule.split(':', 1)
            except ValueError:
                break
            subnode = addnodes.production()
            subnode['tokenname'] = name.strip()
            if subnode['tokenname']:
                idname = nodes.make_id('grammar-token-%s' % subnode['tokenname'])
                if idname not in self.state.document.ids:
                    subnode['ids'].append(idname)
                self.state.document.note_implicit_target(subnode, subnode)
                domain.add_object('token', subnode['tokenname'], self.env.docname, idname)
            subnode.extend(token_xrefs(tokens))
            node.append(subnode)
        return [node]
コード例 #4
0
def productionlist_directive(name, arguments, options, content, lineno,
                             content_offset, block_text, state, state_machine):
    env = state.document.settings.env
    node = addnodes.productionlist()
    messages = []
    i = 0

    for rule in arguments[0].split('\n'):
        if i == 0 and ':' not in rule:
            # production group
            continue
        i += 1
        try:
            name, tokens = rule.split(':', 1)
        except ValueError:
            break
        subnode = addnodes.production()
        subnode['tokenname'] = name.strip()
        if subnode['tokenname']:
            idname = 'grammar-token-%s' % subnode['tokenname']
            if idname not in state.document.ids:
                subnode['ids'].append(idname)
            state.document.note_implicit_target(subnode, subnode)
            env.note_reftarget('token', subnode['tokenname'], idname)
        subnode.extend(token_xrefs(tokens, env))
        node.append(subnode)
    return [node] + messages
コード例 #5
0
ファイル: directives.py プロジェクト: lshmenor/IMTAphy
def productionlist_directive(name, arguments, options, content, lineno,
                             content_offset, block_text, state, state_machine):
    env = state.document.settings.env
    node = addnodes.productionlist()
    messages = []
    i = 0

    for rule in arguments[0].split('\n'):
        if i == 0 and ':' not in rule:
            # production group
            continue
        i += 1
        try:
            name, tokens = rule.split(':', 1)
        except ValueError:
            break
        subnode = addnodes.production()
        subnode['tokenname'] = name.strip()
        if subnode['tokenname']:
            idname = 'grammar-token-%s' % subnode['tokenname']
            if idname not in state.document.ids:
                subnode['ids'].append(idname)
            state.document.note_implicit_target(subnode, subnode)
            env.note_reftarget('token', subnode['tokenname'], idname)
        subnode.extend(token_xrefs(tokens, env))
        node.append(subnode)
    return [node] + messages
コード例 #6
0
ファイル: std.py プロジェクト: alfonsodiecko/PYTHON_DIST
    def run(self):
        env = self.state.document.settings.env
        objects = env.domaindata["std"]["objects"]
        node = addnodes.productionlist()
        messages = []
        i = 0

        for rule in self.arguments[0].split("\n"):
            if i == 0 and ":" not in rule:
                # production group
                continue
            i += 1
            try:
                name, tokens = rule.split(":", 1)
            except ValueError:
                break
            subnode = addnodes.production()
            subnode["tokenname"] = name.strip()
            if subnode["tokenname"]:
                idname = "grammar-token-%s" % subnode["tokenname"]
                if idname not in self.state.document.ids:
                    subnode["ids"].append(idname)
                self.state.document.note_implicit_target(subnode, subnode)
                objects["token", subnode["tokenname"]] = env.docname, idname
            subnode.extend(token_xrefs(tokens))
            node.append(subnode)
        return [node] + messages
コード例 #7
0
ファイル: std.py プロジェクト: xifangzhang/sphinx
    def run(self) -> List[Node]:
        domain = cast(StandardDomain, self.env.get_domain('std'))
        node = addnodes.productionlist()  # type: Element
        self.set_source_info(node)
        # The backslash handling is from ObjectDescription.get_signatures
        nl_escape_re = re.compile(r'\\\n')
        lines = nl_escape_re.sub('', self.arguments[0]).split('\n')

        productionGroup = ""
        i = 0
        for rule in lines:
            if i == 0 and ':' not in rule:
                productionGroup = rule.strip()
                continue
            i += 1
            try:
                name, tokens = rule.split(':', 1)
            except ValueError:
                break
            subnode = addnodes.production(rule)
            subnode['tokenname'] = name.strip()
            if subnode['tokenname']:
                # nodes.make_id converts '_' to '-',
                # so we can use '_' to delimit group from name,
                # and make sure we don't clash with other IDs.
                idname = 'grammar-token-%s_%s' \
                         % (nodes.make_id(productionGroup), nodes.make_id(name))
                if idname not in self.state.document.ids:
                    subnode['ids'].append(idname)

                idnameOld = nodes.make_id('grammar-token-' + name)
                if idnameOld not in self.state.document.ids:
                    subnode['ids'].append(idnameOld)
                self.state.document.note_implicit_target(subnode, subnode)
                if len(productionGroup) != 0:
                    objName = "%s:%s" % (productionGroup, name)
                else:
                    objName = name
                domain.note_object(objtype='token',
                                   name=objName,
                                   labelid=idname,
                                   location=node)
            subnode.extend(token_xrefs(tokens, productionGroup))
            node.append(subnode)
        return [node]
コード例 #8
0
ファイル: std.py プロジェクト: nedbat/sphinx
    def run(self) -> List[Node]:
        domain = cast(StandardDomain, self.env.get_domain('std'))
        node = addnodes.productionlist()  # type: Element
        self.set_source_info(node)
        # The backslash handling is from ObjectDescription.get_signatures
        nl_escape_re = re.compile(r'\\\n')
        lines = nl_escape_re.sub('', self.arguments[0]).split('\n')

        productionGroup = ""
        i = 0
        for rule in lines:
            if i == 0 and ':' not in rule:
                productionGroup = rule.strip()
                continue
            i += 1
            try:
                name, tokens = rule.split(':', 1)
            except ValueError:
                break
            subnode = addnodes.production(rule)
            name = name.strip()
            subnode['tokenname'] = name
            if subnode['tokenname']:
                prefix = 'grammar-token-%s' % productionGroup
                node_id = make_id(self.env, self.state.document, prefix, name)
                subnode['ids'].append(node_id)

                # Assign old styled node_id not to break old hyperlinks (if possible)
                # Note: Will be removed in Sphinx-5.0 (RemovedInSphinx50Warning)
                old_node_id = self.make_old_id(name)
                if (old_node_id not in self.state.document.ids
                        and old_node_id not in subnode['ids']):
                    subnode['ids'].append(old_node_id)

                self.state.document.note_implicit_target(subnode, subnode)

                if len(productionGroup) != 0:
                    objName = "%s:%s" % (productionGroup, name)
                else:
                    objName = name
                domain.note_object('token', objName, node_id, location=node)
            subnode.extend(token_xrefs(tokens, productionGroup))
            node.append(subnode)
        return [node]