Esempio n. 1
0
 public TryStatement(Statement body, TryStatementHandler[] handlers, Statement else_, Statement finally_) {
     _body = body;
     _handlers = handlers;
     _else = else_;
     _finally = finally_;
 }
Esempio n. 2
0
 public override void PostWalk(TryStatementHandler node) { PostWalkWorker(node); }
Esempio n. 3
0
        //except_clause: 'except' [expression [',' expression]]
        //2.6: except_clause: 'except' [expression [(',' or 'as') expression]]
        private TryStatementHandler ParseTryStmtHandler() {
            string exceptWhiteSpace = _tokenWhiteSpace;
            string commaWhiteSpace = null;
            var start = GetStart();
            Expression test1 = null, test2 = null;
            bool altForm = false;
            if (PeekToken().Kind != TokenKind.Colon) {
                test1 = ParseExpression();

                // parse the expression even if the syntax isn't allowed so we
                // report better error messages when opening against the wrong Python version
                var lookahead = _lookahead;
                if (MaybeEat(TokenKind.KeywordAs) || MaybeEatName("as")) {
                    commaWhiteSpace = _tokenWhiteSpace;
                    if (_langVersion < PythonLanguageVersion.V26) {
                        ReportSyntaxError(lookahead.Span.Start, lookahead.Span.End, "'as' requires Python 2.6 or later");
                    }
                    test2 = ParseExpression();
                    altForm = true;
                } else if (MaybeEat(TokenKind.Comma)) {
                    commaWhiteSpace = _tokenWhiteSpace;
                    test2 = ParseExpression();
                    if (_langVersion.Is3x()) {
                        ReportSyntaxError(lookahead.Span.Start, GetEnd(), "\", variable\" not allowed in 3.x - use \"as variable\" instead.");
                    }
                }
            }
            var mid = GetEnd();
            Statement body = ParseSuite();
            TryStatementHandler ret = new TryStatementHandler(test1, test2, body);
            ret.HeaderIndex = mid;
            ret.SetLoc(start, body.EndIndex);

            if (_verbatim) {
                if (altForm) {
                    AddIsAltForm(ret);
                }
                if (commaWhiteSpace != null) {
                    AddSecondPreceedingWhiteSpace(ret, commaWhiteSpace);
                }
                AddPreceedingWhiteSpace(ret, exceptWhiteSpace);
            }
            return ret;
        }
Esempio n. 4
0
 // TryStatementHandler
 public override bool Walk(TryStatementHandler node) { return ShouldWalkWorker(node); }