def source(self): yield 'digraph {id} {{'.format(id=id(self)) yield 'graph [{graph_style}];'.format(graph_style=str(self.graph_style)) yield 'node [{node_style}];'.format(node_style=str(self.node_style)) yield 'edge [{edge_style}];'.format(edge_style=str(self.edge_style)) for node in self.nodes: yield '{id} [{style}];'.format( id=node.id, style=str(node.style) ) for edge in self.edges: yield '{source} -> {target};'.format( source=edge.source, target=edge.target ) yield '}'
def source(self): yield 'digraph G {' yield 'graph [{graph_style}];'.format( graph_style=str(self.graph_style)) yield 'node [{node_style}];'.format(node_style=str(self.node_style)) yield 'edge [{edge_style}];'.format(edge_style=str(self.edge_style)) for node in self.nodes: pattern = ('{index} [{style}];' if node.style else '{index}') yield pattern.format(index=self.id(node.item), style=str(node.style)) for edge in self.edges: pattern = ('{source} -> {target} [{style}];' if edge.style else '{source} -> {target};') yield pattern.format(source=self.id(edge.source), target=self.id(edge.target), style=str(edge.style)) yield '}'
def source(self): yield '{index!r} {token!r}'.format( index=self.index, token=self.token ) yield '----------------' for state in self.states: yield str(state)
def quote(self, value): value = str(value) replace = { '"': r'\"', '\n': r'\n', '\r': r'\r' } for a, b in replace.items(): value = value.replace(a, b) return '"' + value + '"'
def __str__(self): productions = ' | '.join(str(_) for _ in self.productions) if self.optional and self.repeatable: productions += ' *' elif self.optional: productions += ' ?' elif self.repeatable: productions += ' +' return '{name} -> {productions}'.format(name=self.label, productions=productions)
def source(self): yield '{index!r} {token!r}'.format(index=self.index, token=self.token) yield '----------------' for state in self.states: yield str(state)
def __str__(self): productions = ' | '.join(str(_) for _ in self.productions) return '{name} -> {productions}'.format( name=self.label, productions=productions )
def source(self): for rule in self.rules: yield str(rule)