Exemplo n.º 1
0
 def _uncached_match(self, text, pos, cache, error):
     new_pos = pos
     children = []
     while True:
         node = self.members[0].match_core(text, new_pos, cache, error)
         if node is None or not (node.end - node.start):
             # Node was None or 0 length. 0 would otherwise loop infinitely.
             return Node(self.name, text, pos, new_pos, children)
         children.append(node)
         new_pos += node.end - node.start
Exemplo n.º 2
0
        def _uncached_match(self, text, pos, cache, error):
            result = (callable(text, pos) if is_simple else callable(
                text, pos, cache, error, grammar))

            if isinstance(result, integer_types):
                end, children = result, None
            elif isinstance(result, tuple):
                end, children = result
            else:
                # Node or None
                return result
            return Node(self.name, text, pos, end, children=children)
Exemplo n.º 3
0
 def _uncached_match(self, text, pos, cache, error):
     new_pos = pos
     children = []
     while True:
         node = self.members[0].match_core(text, new_pos, cache, error)
         if node is None:
             break
         children.append(node)
         length = node.end - node.start
         if length == 0:  # Don't loop infinitely.
             break
         new_pos += length
     if len(children) >= self.min:
         return Node(self.name, text, pos, new_pos, children)
Exemplo n.º 4
0
 def _uncached_match(self, text, pos, cache, error):
     new_pos = pos
     length_of_sequence = 0
     children = []
     for m in self.members:
         node = m.match_core(text, new_pos, cache, error)
         if node is None:
             return None
         children.append(node)
         length = node.end - node.start
         new_pos += length
         length_of_sequence += length
     # Hooray! We got through all the members!
     return Node(self.name, text, pos, pos + length_of_sequence, children)
Exemplo n.º 5
0
 def _uncached_match(self, text, pos, cache, error):
     node = self.members[0].match_core(text, pos, cache, error)
     return (Node(self.name, text, pos, pos) if node is None else Node(
         self.name, text, pos, node.end, children=[node]))
Exemplo n.º 6
0
 def _uncached_match(self, text, pos, cache, error):
     # FWIW, the implementation in Parsing Techniques in Figure 15.29 does
     # not bother to cache NOTs directly.
     node = self.members[0].match_core(text, pos, cache, error)
     if node is None:
         return Node(self.name, text, pos, pos)
Exemplo n.º 7
0
 def _uncached_match(self, text, pos, cache, error):
     node = self.members[0].match_core(text, pos, cache, error)
     if node is not None:
         return Node(self.name, text, pos, pos)
Exemplo n.º 8
0
 def _uncached_match(self, text, pos, cache, error):
     for m in self.members:
         node = m.match_core(text, pos, cache, error)
         if node is not None:
             # Wrap the succeeding child in a node representing the OneOf:
             return Node(self.name, text, pos, node.end, children=[node])
Exemplo n.º 9
0
 def _uncached_match(self, token_list, pos, cache, error):
     if token_list[pos].type == self.literal:
         return Node(self.name, token_list, pos, pos + 1)
Exemplo n.º 10
0
 def _uncached_match(self, text, pos, cache, error):
     if text.startswith(self.literal, pos):
         return Node(self.name, text, pos, pos + len(self.literal))