Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
    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]
Beispiel #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
Beispiel #5
0
    def run(self):
        # type: () -> List[nodes.Node]
        env = self.state.document.settings.env
        objects = env.domaindata['std']['objects']
        node = addnodes.productionlist()
        messages = []  # type: List[nodes.Node]
        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
Beispiel #6
0
    def run(self) -> List[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]
Beispiel #7
0
    def run(self):
        env = self.state.document.settings.env
        objects = env.domaindata['std']['objects']

        class ProdnError(Exception):
            """Exception for ill-formed prodn"""
            pass

        [idx, node] = super().run()
        try:
            # find LHS of production
            inline_lhs = node[0][0][0][0]  # may be fragile !!!
            lhs_str = str(inline_lhs)
            if lhs_str[0:7] != "<inline":
                raise ProdnError("Expected atom on LHS")
            lhs = inline_lhs[0]
            # register link target
            subnode = addnodes.production()
            subnode['tokenname'] = lhs
            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(lhs))
            # patch in link target
            inline_lhs['ids'].append(idname)
        except ProdnError as err:
            getLogger(__name__).warning(
                "Could not create link target for prodn: " + str(err) +
                "\nSphinx represents the prodn as: " + str(node) + "\n")
        return [idx, node]
Beispiel #8
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
Beispiel #9
0
    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]
Beispiel #10
0
    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]