Esempio n. 1
0
        //raise_stmt: 'raise' [expression [',' expression [',' expression]]]
        private RaiseStatement ParseRaiseStmt()
        {
            Eat(TokenKind.KeywordRaise);
            string raiseWhiteSpace = _tokenWhiteSpace;
            string commaWhiteSpace = null, secondCommaWhiteSpace = null;
            var start = GetStart();
            Expression type = null, value = null, traceback = null, cause = null;
            bool isFromForm = false;

            if (!NeverTestToken(PeekToken())) {
                type = ParseExpression();

                if (MaybeEat(TokenKind.Comma)) {
                    var commaStart = GetStart();
                    commaWhiteSpace = _tokenWhiteSpace;
                    value = ParseExpression();
                    if (!_langVersion.Is6x()) {
                        ReportSyntaxError(commaStart, GetEnd(), "invalid syntax, only exception value is allowed in 3.x.");
                    }
                    if (MaybeEat(TokenKind.Comma)) {
                        secondCommaWhiteSpace = _tokenWhiteSpace;
                        traceback = ParseExpression();
                    }
                } else if (MaybeEat(TokenKind.KeywordFrom)) {
                    commaWhiteSpace = _tokenWhiteSpace;
                    var fromStart = GetStart();
                    cause = ParseExpression();
                    isFromForm = true;

                    if (!_langVersion.Is7x()) {
                       ReportSyntaxError(fromStart, cause.EndIndex, "invalid syntax, from cause not allowed in 2.x.");
                    }
                }

            }
            RaiseStatement ret = new RaiseStatement(type, value, traceback, cause);
            if (_verbatim) {
                AddPreceedingWhiteSpace(ret, raiseWhiteSpace);
                AddSecondPreceedingWhiteSpace(ret, commaWhiteSpace);
                AddThirdPreceedingWhiteSpace(ret, secondCommaWhiteSpace);
                if (isFromForm) {
                    AddIsAltForm(ret);
                }
            }

            ret.SetLoc(start, GetEnd());
            return ret;
        }
Esempio n. 2
0
 public override bool Walk(RaiseStatement node)
 {
     UpdateChildRanges(node);
     return base.Walk(node);
 }
Esempio n. 3
0
 public override void PostWalk(RaiseStatement node)
 {
     PostWalkWorker(node);
 }
Esempio n. 4
0
 // RaiseStatement
 public override bool Walk(RaiseStatement node)
 {
     return ShouldWalkWorker(node);
 }
Esempio n. 5
0
 public override bool Walk(RaiseStatement node)
 {
     _raises = true;
     return base.Walk(node);
 }