Ejemplo n.º 1
0
 def relex_import(self, startnode, version = 0):
     """Optimised relex for freshly imported files."""
     success = self.lex(startnode.symbol.name)
     bos = startnode.prev_term # bos
     parent = bos.parent
     eos = parent.children.pop()
     last_node = bos
     for match in success:
         if match is success[0]:
             # reuse old node for fist node to mimic the behaviour of a
             # normal relex
             node = startnode
             node.symbol.name = match[0]
         else:
             node = TextNode(Terminal(match[0]))
         node.lookup = match[1]
         parent.children.append(node)
         last_node.next_term = node
         last_node.right = node
         node.left = last_node
         node.prev_term = last_node
         node.parent = parent
         last_node = node
         node.mark_changed()
     parent.children.append(eos)
     last_node.right = eos # link to eos
     last_node.next_term = eos
     eos.left = last_node
     eos.prev_term = last_node
     bos.mark_changed()
     eos.mark_changed()
     parent.mark_changed()
Ejemplo n.º 2
0
 def relex_import(self, startnode, version = 0):
     """
     Replace a node with the tokens of its name
     :param startnode: node to expand
     :param version: version assigned to each created node
     :return:
     """
     success = self.lex(startnode.symbol.name)
     bos = startnode.prev_term # bos
     startnode.parent.remove_child(startnode)
     parent = bos.parent
     eos = parent.children.pop()
     last_node = bos
     for match in success:
         node = TextNode(Terminal(match[0]))
         node.version = version
         node.lookup = match[1]
         parent.children.append(node)
         last_node.next_term = node
         last_node.right = node
         node.left = last_node
         node.prev_term = last_node
         node.parent = parent
         last_node = node
     parent.children.append(eos)
     last_node.right = eos # link to eos
     last_node.next_term = eos
     eos.left = last_node
     eos.prev_term = last_node
Ejemplo n.º 3
0
 def relex_import(self, startnode):
     success = self.lex(startnode.symbol.name)
     bos = startnode.prev_term # bos
     startnode.parent.remove_child(startnode)
     parent = bos.parent
     eos = parent.children.pop()
     last_node = bos
     for match in success:
         node = TextNode(Terminal(match[0]))
         node.lookup = match[1]
         parent.children.append(node)
         last_node.next_term = node
         last_node.right = node
         node.left = last_node
         node.prev_term = last_node
         node.parent = parent
         last_node = node
     parent.children.append(eos)
     last_node.right = eos # link to eos
     last_node.next_term = eos
     eos.left = last_node
     eos.prev_term = last_node
Ejemplo n.º 4
0
 def relex_import(self, startnode, version=0):
     success = self.lex(startnode.symbol.name)
     bos = startnode.prev_term # bos
     startnode.parent.remove_child(startnode)
     parent = bos.parent
     eos = parent.children.pop()
     last_node = bos
     for match in success:
         node = TextNode(Terminal(match[0]))
         node.version = version
         node.lookup = match[1]
         parent.children.append(node)
         last_node.next_term = node
         last_node.right = node
         node.left = last_node
         node.prev_term = last_node
         node.parent = parent
         last_node = node
     parent.children.append(eos)
     last_node.right = eos # link to eos
     last_node.next_term = eos
     eos.left = last_node
     eos.prev_term = last_node