コード例 #1
0
ファイル: Comprehension.cs プロジェクト: omnimark/PTVS
 public DictionaryComprehension(SliceExpression value, ComprehensionIterator[] iterators) {
     _value = value;
     _iterators = iterators;
 }
コード例 #2
0
ファイル: Parser.cs プロジェクト: omnimark/PTVS
        /*
        // "for" target_list "in" or_test
        private ForStatement ParseGenExprFor() {
            var start = GetStart();
            Eat(TokenKind.KeywordFor);
            bool trailingComma;
            List<string> listWhiteSpace;
            List<Expression> l = ParseTargetList(out trailingComma, out listWhiteSpace);
            Expression lhs = MakeTupleOrExpr(l, listWhiteSpace, trailingComma);
            Eat(TokenKind.KeywordIn);

            Expression expr = null;
            expr = ParseOrTest();

            ForStatement gef = new ForStatement(lhs, expr, null, null);
            var end = GetEnd();
            gef.SetLoc(start, end);
            gef.HeaderIndex = end;
            return gef;
        }

        //  genexpr_if: "if" old_test
        private IfStatement ParseGenExprIf() {
            var start = GetStart();
            Eat(TokenKind.KeywordIf);
            Expression expr = ParseOldExpression();
            IfStatementTest ist = new IfStatementTest(expr, null);
            var end = GetEnd();
            ist.HeaderIndex = end;
            ist.SetLoc(start, end);
            IfStatement gei = new IfStatement(new IfStatementTest[] { ist }, null);
            gei.SetLoc(start, end);
            return gei;
        }
        */

        // dict_display: '{' [dictorsetmaker] '}'
        // dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |
        //                   (test (comp_for | (',' test)* [','])) )


        private Expression FinishDictOrSetValue() {
            string startWhiteSpace = _tokenWhiteSpace, finishWhiteSpace;
            var oStart = GetStart();
            var oEnd = GetEnd();

            List<SliceExpression> dictMembers = null;
            List<Expression> setMembers = null;
            List<string> itemWhiteSpace = MakeWhiteSpaceList();
            bool prevAllow = _allowIncomplete;
            bool reportedError = false;
            bool ateTerminator = false;
            try {
                _allowIncomplete = true;
                while (true) {
                    if (MaybeEat(TokenKind.RightBrace)) { // empty dict literal
                        finishWhiteSpace = _tokenWhiteSpace;
                        ateTerminator = true;
                        break;
                    }
                    bool first = false;
                    Expression e1 = ParseExpression();
                    if (MaybeEat(TokenKind.Colon)) { // dict literal
                        string colonWhiteSpace = _tokenWhiteSpace;
                        if (setMembers == null && dictMembers == null) {
                            dictMembers = new List<SliceExpression>();
                            first = true;
                        }
                        Expression e2 = ParseExpression();

                        if (setMembers != null) {
                            if (!reportedError) {
                                ReportSyntaxError(e1.StartIndex, e2.EndIndex, "invalid syntax");
                            }
                        }


                        SliceExpression se = new SliceExpression(e1, e2, null, false);
                        if (_verbatim) {
                            AddPreceedingWhiteSpace(se, colonWhiteSpace);
                        }
                        se.SetLoc(e1.StartIndex, e2.EndIndex);

                        if (PeekToken(Tokens.KeywordForToken)) {
                            if (!first || _langVersion < PythonLanguageVersion.V27) {
                                ReportSyntaxError("invalid syntax");
                            }

                            var dictComp = FinishDictComp(se, out ateTerminator);
                            if (_verbatim) {
                                AddPreceedingWhiteSpace(dictComp, startWhiteSpace);
                                AddSecondPreceedingWhiteSpace(dictComp, _tokenWhiteSpace);
                                if (!ateTerminator) {
                                    AddErrorMissingCloseGrouping(dictComp);
                                }
                            }
                            dictComp.SetLoc(oStart, GetEnd());
                            return dictComp;
                        }

                        if (dictMembers != null) {
                            dictMembers.Add(se);
                        } else {
                            setMembers.Add(se);
                        }
                    } else { // set literal
                        if (_langVersion < PythonLanguageVersion.V27 && !reportedError) {
                            ReportSyntaxError(e1.StartIndex, e1.EndIndex, "invalid syntax, set literals require Python 2.7 or later.");
                            reportedError = true;
                        }
                        if (dictMembers != null) {
                            if (!reportedError) {
                                ReportSyntaxError(e1.StartIndex, e1.EndIndex, "invalid syntax");
                            }
                        } else if (setMembers == null) {
                            setMembers = new List<Expression>();
                            first = true;
                        }

                        if (PeekToken(Tokens.KeywordForToken)) {
                            if (!first) {
                                ReportSyntaxError("invalid syntax");
                            }
                            var setComp = FinishSetComp(e1, out ateTerminator);
                            if (_verbatim) {
                                AddPreceedingWhiteSpace(setComp, startWhiteSpace);
                                AddSecondPreceedingWhiteSpace(setComp, _tokenWhiteSpace);
                                if (!ateTerminator) {
                                    AddErrorMissingCloseGrouping(setComp);
                                }
                            }
                            setComp.SetLoc(oStart, GetEnd());
                            return setComp;
                        }

                        // error recovery
                        if (setMembers != null) {
                            setMembers.Add(e1);
                        } else {
                            var slice = new SliceExpression(e1, null, null, false);
                            if (_verbatim) {
                                AddErrorIsIncompleteNode(slice);
                            }
                            dictMembers.Add(slice);
                        }
                    }

                    if (!MaybeEat(TokenKind.Comma)) {
                        ateTerminator = Eat(TokenKind.RightBrace);
                        finishWhiteSpace = _tokenWhiteSpace;
                        break;
                    }
                    if (itemWhiteSpace != null) {
                        itemWhiteSpace.Add(_tokenWhiteSpace);
                    }
                }
            } finally {
                _allowIncomplete = prevAllow;
            }


            var cStart = GetStart();
            var cEnd = GetEnd();

            Expression ret;
            if (dictMembers != null || setMembers == null) {
                SliceExpression[] exprs;
                if (dictMembers != null) {
                    exprs = dictMembers.ToArray();
                } else {
                    exprs = new SliceExpression[0];
                }
                ret = new DictionaryExpression(exprs);
            } else {
                ret = new SetExpression(setMembers.ToArray());
            }
            ret.SetLoc(oStart, cEnd);
            if (_verbatim) {
                AddPreceedingWhiteSpace(ret, startWhiteSpace);
                AddSecondPreceedingWhiteSpace(ret, finishWhiteSpace);
                AddListWhiteSpace(ret, itemWhiteSpace.ToArray());
                if (!ateTerminator) {
                    AddErrorMissingCloseGrouping(ret);
                }
            }
            return ret;
        }
コード例 #3
0
ファイル: Parser.cs プロジェクト: omnimark/PTVS
 // comp_iter '}'
 private DictionaryComprehension FinishDictComp(SliceExpression value, out bool ateTerminator) {
     ComprehensionIterator[] iters = ParseCompIter();
     ateTerminator = Eat(TokenKind.RightBrace);
     return new DictionaryComprehension(value, iters);
 }
コード例 #4
0
ファイル: Parser.cs プロジェクト: omnimark/PTVS
        private Expression FinishSlice(Expression e0, int start) {
            Expression e1 = null;
            Expression e2 = null;
            bool stepProvided = false;
            Debug.Assert(_token.Token.Kind == TokenKind.Colon);
            string colonWhiteSpace = _tokenWhiteSpace;
            string secondColonWhiteSpace = null;

            switch (PeekToken().Kind) {
                case TokenKind.Comma:
                case TokenKind.RightBracket:
                    break;
                case TokenKind.Colon:
                    // x[?::?]
                    stepProvided = true;
                    NextToken();
                    secondColonWhiteSpace = _tokenWhiteSpace;
                    e2 = ParseSliceEnd();
                    break;
                default:
                    // x[?:val:?]
                    e1 = ParseExpression();
                    if (MaybeEat(TokenKind.Colon)) {
                        secondColonWhiteSpace = _tokenWhiteSpace;
                        stepProvided = true;
                        e2 = ParseSliceEnd();
                    }
                    break;
            }
            SliceExpression ret = new SliceExpression(e0, e1, e2, stepProvided);
            if (_verbatim) {
                AddPreceedingWhiteSpace(ret, colonWhiteSpace);
                if (secondColonWhiteSpace != null) {
                    AddSecondPreceedingWhiteSpace(ret, secondColonWhiteSpace);
                }
            }
            ret.SetLoc(start, GetEnd());
            return ret;
        }
コード例 #5
0
ファイル: CoverageMapper.cs プロジェクト: jsschultz/PTVS
 public override bool Walk(SliceExpression node) {
     return UpdateLineInfo(node, true);
 }
コード例 #6
0
ファイル: Comprehension.cs プロジェクト: szh2bg/PTVS
 public DictionaryComprehension(SliceExpression value, ComprehensionIterator[] iterators)
 {
     _value     = value;
     _iterators = iterators;
 }
コード例 #7
0
ファイル: EnclosingNodeWalker.cs プロジェクト: omnimark/PTVS
 public override void PostWalk(SliceExpression node) { PostWalkWorker(node); }
コード例 #8
0
ファイル: EnclosingNodeWalker.cs プロジェクト: omnimark/PTVS
 // SliceExpression
 public override bool Walk(SliceExpression node) { return ShouldWalkWorker(node); }