pyrser/passes/topython.py
def visit_Alt(self, node: parsing.Alt) -> [ast.stmt]:
        """Generates python code for alternatives.

        try:
            try:
                <code for clause>  #raise AltFalse when alternative is False
                raise AltTrue()
            except AltFalse:
                pass
            return False
        except AltTrue:
            pass
        """
        clauses = [self.visit(clause) for clause in node.ptlist]
        for clause in clauses:
            if not isinstance(clause, ast.expr):
                break
        else:
            return ast.BoolOp(ast.Or(), clauses)
        res = ast.Try([], [ast.ExceptHandler(
            ast.Name('AltTrue', ast.Load()), None, [ast.Pass()])], [], [])
        alt_true = [ast.Raise(ast.Call(
            ast.Name('AltTrue', ast.Load()), [], [], None, None), None)]
        alt_false = [ast.ExceptHandler(
            ast.Name('AltFalse', ast.Load()), None, [ast.Pass()])]
        self.in_try += 1
        for clause in node.ptlist:
            res.body.append(
                ast.Try(self._clause(self.visit(clause)) + alt_true,
                        alt_false, [], []))
        self.in_try -= 1
        res.body.append(self.__exit_scope())
        return [res]
def visit_Alt(self, node: parsing.Alt) -> [ast.stmt]:
        clauses = [self.visit(clause) for clause in node.ptlist]
        for clause in clauses:
            if not isinstance(clause, ast.expr):
                break
        else:
            return ast.BoolOp(ast.Or(), clauses)
        res = ast.Try([], [ast.ExceptHandler(
            ast.Name('AltTrue', ast.Load()), None, [ast.Pass()])], [], [])
        alt_true = [ast.Raise(ast.Call(
            ast.Name('AltTrue', ast.Load()), [], [], None, None), None)]
        alt_false = [ast.ExceptHandler(
            ast.Name('AltFalse', ast.Load()), None, [ast.Pass()])]
        self.in_try += 1
        for clause in node.ptlist:
            res.body.append(
                ast.Try(self._clause(self.visit(clause)) + alt_true,
                        alt_false, [], []))
        self.in_try -= 1
        res.body.append(self.__exit_scope())
        return [res]
def visit_Alt ( self , node : parsing . Alt ) -> [ ast . stmt ] : clauses = [ self . visit ( clause ) for clause in node . ptlist ] for clause in clauses : if not isinstance ( clause , ast . expr ) : break else : return ast . BoolOp ( ast . Or ( ) , clauses ) res = ast . Try ( [ ] , [ ast . ExceptHandler ( ast . Name ( 'AltTrue' , ast . Load ( ) ) , None , [ ast . Pass ( ) ] ) ] , [ ] , [ ] ) alt_true = [ ast . Raise ( ast . Call ( ast . Name ( 'AltTrue' , ast . Load ( ) ) , [ ] , [ ] , None , None ) , None ) ] alt_false = [ ast . ExceptHandler ( ast . Name ( 'AltFalse' , ast . Load ( ) ) , None , [ ast . Pass ( ) ] ) ] self . in_try += 1 for clause in node . ptlist : res . body . append ( ast . Try ( self . _clause ( self . visit ( clause ) ) + alt_true , alt_false , [ ] , [ ] ) ) self . in_try -= 1 res . body . append ( self . __exit_scope ( ) ) return [ res ]
Generates python code for alternatives.

        try:
            try:
                <code for clause>  #raise AltFalse when alternative is False
                raise AltTrue()
            except AltFalse:
                pass
            return False
        except AltTrue:
            pass
Generates python code for alternatives .