def render_fields(self, fields): abstract_template = trim(self.abstract_rule_template) abstract_rules = [ abstract_template.format(parsername=fields['name'], name=rule.name) for rule in self.node.rules ] abstract_rules = indent('\n'.join(abstract_rules)) abstract_py_template = trim(self.abstract_rule_py_template) abstract_rules_py = [ abstract_py_template.format(parsername=fields['name'], name=rule.name) for rule in self.node.rules ] abstract_rules_py = indent('\n'.join(abstract_rules_py)) rule_template = trim(self.rule_template) rules = [ rule_template.format(parsername=fields['name'], name=rule.name) for rule in self.node.rules ] rules = '\n'.join(rules) if self.node.statetype is not None: statetype_arg = ", " + self.node.statetype else: statetype_arg = "" version = str(tuple(int(n) for n in str(timestamp()).split('.'))) fields.update(rules=indent(rules), abstract_rules=abstract_rules, abstract_rules_py=abstract_rules_py, version=version, statetype_arg=statetype_arg )
def render_fields(self, fields): abstract_template = trim(self.abstract_rule_template) abstract_rules = [ abstract_template.format(parsername=fields['name'], name=rule.name) for rule in self.node.rules ] abstract_rules = indent(''.join(abstract_rules), 2) rule_template = trim(self.rule_template) rules = [ rule_template.format(parsername=fields['name'], name=rule.name) for rule in self.node.rules ] rules = indent(''.join(rules), 2) if self.node.statetype is None: statetype_arg = ", int" else: statetype_arg = ", " + self.node.statetype version = str(tuple(int(n) for n in str(timestamp()).split('.'))) fields.update(abstract_rules=abstract_rules, rules=rules, version=version, statetype_arg=statetype_arg)
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', False) parseinfo = self.node.directives.get('parseinfo', True) namechars = urepr(self.node.directives.get('namechars') or '') 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('.'))) keywords = '\n'.join(" %s," % urepr(k) for k in sorted(self.keywords)) if keywords: keywords = '\n%s\n' % keywords fields.update( rules=indent(rules), abstract_rules=abstract_rules, version=version, whitespace=whitespace, nameguard=nameguard, ignorecase=ignorecase, comments_re=comments_re, eol_comments_re=eol_comments_re, left_recursion=left_recursion, parseinfo=parseinfo, keywords=keywords, namechars=namechars, )
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', False) parseinfo = self.node.directives.get('parseinfo', True) namechars = urepr(self.node.directives.get('namechars') or '') 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('.'))) keywords = '\n'.join(" %s," % urepr(k) for k in sorted(self.keywords)) if keywords: keywords = '\n%s\n' % keywords fields.update(rules=indent(rules), abstract_rules=abstract_rules, version=version, whitespace=whitespace, nameguard=nameguard, ignorecase=ignorecase, comments_re=comments_re, eol_comments_re=eol_comments_re, left_recursion=left_recursion, parseinfo=parseinfo, keywords=keywords, namechars=namechars, )
def render_fields(self, fields): abstract_template = trim(self.abstract_rule_template) abstract_rules = [ abstract_template.format(parsername=fields['name'], classname=fields['name'], name=rule.name) for rule in self.node.rules ] abstract_rules = '\n'.join(abstract_rules) if self.node.whitespace is not None: whitespace = "set_whitespace(" + cpp_repr( self.node.whitespace) + ");" else: whitespace = "// use default whitespace setting" if self.node.nameguard is not None: nameguard = 'true' if self.node.nameguard else 'false' nameguard = "set_nameguard(" + nameguard + ");" else: nameguard = "// use default nameguard setting" rules = '\n'.join([ self.get_renderer(rule).render(classname=fields['name']) for rule in self.node.rules ]) findruleitems = '\n'.join([ '{ "%s", &%sParser::_%s_ },' % (rule.name, fields['name'], rule.name) for rule in self.node.rules ]) version = str(tuple(int(n) for n in str(timestamp()).split('.'))) fields.update(rules=rules, findruleitems=indent(findruleitems), abstract_rules=abstract_rules, version=version, whitespace=whitespace, nameguard=nameguard)
def render_fields(self, fields): abstract_template = trim(self.abstract_rule_template) abstract_rules = [ abstract_template.format(parsername=fields['name'], classname=fields['name'], name=rule.name) for rule in self.node.rules ] abstract_rules = '\n'.join(abstract_rules) if self.node.whitespace is not None: whitespace = "set_whitespace(" + cpp_repr(self.node.whitespace) + ");" else: whitespace = "// use default whitespace setting" if self.node.nameguard is not None: nameguard = 'true' if self.node.nameguard else 'false' nameguard = "set_nameguard(" + nameguard + ");" else: nameguard = "// use default nameguard setting" rules = '\n'.join([ self.get_renderer(rule).render(classname=fields['name']) for rule in self.node.rules ]) findruleitems = '\n'.join([ '{ "%s", &%sParser::_%s_ },' % (rule.name, fields['name'], rule.name) for rule in self.node.rules ]) version = str(tuple(int(n) for n in str(timestamp()).split('.'))) fields.update(rules=rules, findruleitems=indent(findruleitems), abstract_rules=abstract_rules, version=version, whitespace=whitespace, nameguard=nameguard )