Esempio n. 1
0
File: dot.py Progetto: stcoder/yargy
 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 '}'
Esempio n. 2
0
 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 '}'
Esempio n. 3
0
 def source(self):
     yield '{index!r} {token!r}'.format(
         index=self.index,
         token=self.token
     )
     yield '----------------'
     for state in self.states:
         yield str(state)
Esempio n. 4
0
File: dot.py Progetto: stcoder/yargy
 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 + '"'
Esempio n. 5
0
File: bnf.py Progetto: stcoder/yargy
 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)
Esempio n. 6
0
 def source(self):
     yield '{index!r} {token!r}'.format(index=self.index, token=self.token)
     yield '----------------'
     for state in self.states:
         yield str(state)
Esempio n. 7
0
 def __str__(self):
     productions = ' | '.join(str(_) for _ in self.productions)
     return '{name} -> {productions}'.format(
         name=self.label,
         productions=productions
     )
Esempio n. 8
0
 def source(self):
     for rule in self.rules:
         yield str(rule)