def parse(self, texts, pos=0): """Return a parse tree of each ``text`` in list of ``texts``. Raise ``ParseError`` if the expression wasn't satisfied. Raise ``IncompleteParseError`` if the expression was satisfied but didn't consume the full string. """ # if we have a list of texts, vectorize it # TODO: fix that this raises error if any one of the nodes fails # instead just remove node? if self.is_list_of_strings(texts): texts = np.array(texts) vec_match = np.vectorize(self.match) nodes = vec_match(texts) for i, node in enumerate(nodes): if node.end < len(texts[i]): raise IncompleteParseError(texts[i], node.end, self) return nodes else: # otherwise, proceed normally node = self.match(texts, pos=pos) if node.end < len(texts): raise IncompleteParseError(texts, node.end, self) return node
def parse(self, text, pos=0): """Return a parse tree of ``text``. Raise ``ParseError`` if the expression wasn't satisfied. Raise ``IncompleteParseError`` if the expression was satisfied but didn't consume the full string. """ node = self.match(text, pos=pos) if node.end < len(text): e = IncompleteParseError(text, node.end, self) e.node = node raise e return node
def parse(self, text, pos=0): """Return a parse tree of ``text``. Raise ``ParseError`` if the expression wasn't satisfied. Raise ``IncompleteParseError`` if the expression was satisfied but didn't consume the full string. """ node = self.match(text, pos=pos) if node.end < len(text): e = IncompleteParseError(text, node.end, self) e.node = node raise e return node