def next_item(item: Item) -> Item: """Advance to the next item of the stream. The stream is left unchanged. NoCatch Exception if accumulated nonempty. Nonempty would be a bug in this program. """ if item.pos >= len(item.stream): raise ParseError(ErrorItem(item=item, nonterminal='eof')) #StopIteration if item.acc: raise ParseNoCatch([ErrorItem(item=item, nonterminal='.')]) return Item(pos=item.pos + 1, stream=item.stream, acc=item.stream[item.pos])
def f(item): item1 = self.process(item) try: item2 = tokenlib.update(treatment(item1.acc),item1) return item2 except ParseError as pe: nonterminal=msg.setdefault(name,'treat') raise ParseError(ErrorItem(item=item,nonterminal=nonterminal)) from pe
def f(item): try: item1 = self.process(item) acc = item1.acc its1 = [tokenlib.Item(stream=a,pos=0,acc=None) for a in acc] acc2 = [(p2 + Parse.finished()).treat(lib.fst).process(it).acc for it in its1] item3 = tokenlib.update(acc2,item1) return item3 except ParseError as pe: raise ParseError(ErrorItem(item=item,nonterminal='reparse_list-'+p2.nonterminal)) from pe
def f(item): try: item0 = self.process(item) acc = item0.acc if not acc: return item item1 = tokenlib.Item(stream=acc,pos=0,acc=None) item2 = (self + Parse.finished()).treat(lib.fst).process(item1) item3 = tokenlib.update(item2.acc,item0) return item3 except ParseError as pe: raise ParseError(ErrorItem(item=item1,nonterminal='reparse-'+p2.nonterminal)) from pe
def process(self,item): # sample mode if state.mk_sample: acc = self.sample() return tokenlib.update(acc,item) # process mode, the front door. try: return self._process(item) except ParseError as pe: ei = pe.error_stack nt = ei.nonterminal if self.nonterminal or self.production: nt = f'({nt}; {self})' #As a last resort try a backdoor, nonterminal as terminal... #the backdoor should never raise an exception. if not(tokenlib.eof(item)): item1 = tokenlib.next_item(item) if item1.acc.value == self.nonterminal: acc = Etok.etok(item1.acc) return tokenlib.update(acc,item1) raise ParseError(ErrorItem(item=ei.item, nonterminal=nt))
def sample(self): if not(self._sample): raise ParseError(ErrorItem(item=None,nonterminal=f'sample not installed: {self.nonterminal}-{self.production}')) return self._sample()
def f(item): raise ParseError(ErrorItem(item=item,nonterminal='first-empty'))
def f(item): item1 = self.process(item) if p(item1.acc): return item1 else: raise ParseError(ErrorItem(item=item,nonterminal=f'{self.nonterminal}-if-{self.production}'))
def f(item): try: return self.process(item) except ParseError as pe: nonterminal= msg.setdefault(nt,'nocatch') raise ParseNoCatch(ErrorItem(item=item,nonterminal=nonterminal)) from pe
def f(item): try: self.process(item) return item except ParseError as pe: raise ParseError(ErrorItem(item=item,nonterminal='-probe')) from pe
def f(item): raise ParseError(ErrorItem(item=item,nonterminal='fail'))
def f(item): if item.pos < len(item.stream): raise ParseError(ErrorItem(item=item,nonterminal='$')) return item