Beispiel #1
0
    def render_fields(self, fields):
        abstract_template = trim(self.abstract_rule_template)
        abstract_rules = [abstract_template.format(name=safe_name(rule.name)) for rule in self.node.rules]
        abstract_rules = indent("\n".join(abstract_rules))

        if self.node.whitespace is not None:
            whitespace = urepr(self.node.whitespace)
        elif self.node.directives.get("whitespace") is not None:
            whitespace = "re.compile({0}, RE_FLAGS | re.DOTALL)".format(urepr(self.node.directives.get("whitespace")))
        else:
            whitespace = "None"

        if self.node.nameguard is not None:
            nameguard = urepr(self.node.nameguard)
        elif self.node.directives.get("nameguard") is not None:
            nameguard = self.node.directives.get("nameguard")
        else:
            nameguard = "None"

        comments_re = urepr(self.node.directives.get("comments"))
        eol_comments_re = urepr(self.node.directives.get("eol_comments"))
        ignorecase = self.node.directives.get("ignorecase", "None")
        left_recursion = self.node.directives.get("left_recursion", True)

        rules = "\n".join([self.get_renderer(rule).render() for rule in self.node.rules])

        version = str(tuple(int(n) for n in str(timestamp()).split(".")))

        fields.update(
            rules=indent(rules),
            abstract_rules=abstract_rules,
            version=version,
            whitespace=whitespace,
            nameguard=nameguard,
            comments_re=comments_re,
            eol_comments_re=eol_comments_re,
            ignorecase=ignorecase,
            left_recursion=left_recursion,
        )
Beispiel #2
0
 def render_fields(self, fields):
     fields.update(n=self.counter(), name=safe_name(self.node.name))