Esempio n. 1
0
        private Statement ParseReturnStmt()
        {
            if (CurrentFunction == null) {
                ReportSyntaxError("'return' outside function");
            }
            var returnToken = _lookahead;
            NextToken();
            string returnWhitespace = _tokenWhiteSpace;
            Expression expr = null;
            var start = GetStart();
            if (!NeverTestToken(PeekToken())) {
                expr = ParseTestListAsExpr();
            }

            if (expr != null && _langVersion < JLanguageVersion.V33) {
                if (_isGenerator) {
                    ReportSyntaxError(returnToken.Span.Start, expr.EndIndex, "'return' with argument inside generator");
                } else {
                    if (_returnsWithValue == null) {
                        _returnsWithValue = new List<IndexSpan>();
                    }
                    _returnsWithValue.Add(new IndexSpan(returnToken.Span.Start, expr.EndIndex - returnToken.Span.Start));
                }
            }

            ReturnStatement ret = new ReturnStatement(expr);
            if (_verbatim) {
                AddPreceedingWhiteSpace(ret, returnWhitespace);
            }
            ret.SetLoc(start, GetEnd());
            return ret;
        }
Esempio n. 2
0
 public JAst ParseTopExpression()
 {
     // TODO: move from source unit  .TrimStart(' ', '\t')
     ReturnStatement ret = new ReturnStatement(ParseTestListAsExpression());
     ret.SetLoc(0, 0);
     return CreateAst(ret);
 }