def switchcase(self): self.ignore(whitespace) self.nextmust('switch') self.ignore(whitespace) varn = self.varvalu() self.ignore(whitespace) self.nextmust('{') kids = [varn] while self.more(): self.ignorespace() if self.nextstr('}'): self.offs += 1 break if self.nextstr('*'): self.offs += 1 self.ignore(whitespace) self.nextmust(':') subq = self.subquery() cent = s_ast.CaseEntry(kids=[subq]) kids.append(cent) continue valu = self.casevalu() if not isinstance(valu, s_ast.Const): self._raiseSyntaxError('Switch case syntax only supports const values.') self.ignorespace() subq = self.subquery() cent = s_ast.CaseEntry(kids=[valu, subq]) kids.append(cent) return s_ast.SwitchCase(kids=kids)
def switchcase(self, kids): newkids = [] it = iter(kids) varvalu = next(it) newkids.append(varvalu) for casekid, sqkid in zip(it, it): subquery = self._convert_child(sqkid) if casekid.type == 'DEFAULTCASE': caseentry = s_ast.CaseEntry(kids=[subquery]) else: casekid = self._convert_child(casekid) caseentry = s_ast.CaseEntry(kids=[casekid, subquery]) newkids.append(caseentry) return s_ast.SwitchCase(newkids)