private InitializerExpressionNode parseObjectOrCollectionInitializer() {
            if (isIdentifier(lexicalUnit)) {
                var restorePoint = this.createRestorePoint();
                int sp = scanner.StartPosition;
                int len = getLexicalUnitLength();
                saveScannerState();
                if (nextLexicalUnit(true) == LexicalUnit.Assign) {
                    var objectInitializer = new ObjectInitializerExpressionNode();
                    setSavedScannerState(objectInitializer);
                    var memberInitializer = new MemberInitializerNode { NameOffset = sp, NameLength = len };
                    setSavedScannerState(memberInitializer);
                    if (nextLexicalUnit(true) == LexicalUnit.OpenBrace) {
                        nextLexicalUnit(true);
                        memberInitializer.Value = parseObjectOrCollectionInitializer();
                    } else {
                        memberInitializer.Value = parseExpression();
                    }
                    memberInitializer.EndPosition = memberInitializer.Value.EndPosition;
                    objectInitializer.MemberInitializers.add(memberInitializer);
                    while (lexicalUnit == LexicalUnit.Comma) {
                        if (!isIdentifier(nextLexicalUnit(true))) {
                            break;
                        }
                        sp = scanner.StartPosition;
                        len = getLexicalUnitLength();
		                saveScannerState();
                        if (nextLexicalUnit(true) != LexicalUnit.Assign) {
                            throw error(ParseErrorId.AssignExpected);
                        }
                        memberInitializer = new MemberInitializerNode { NameOffset = sp, NameLength = len };
	                    setSavedScannerState(memberInitializer);
                        if (nextLexicalUnit(true) == LexicalUnit.OpenBrace) {
                            nextLexicalUnit(true);
                            memberInitializer.Value = parseObjectOrCollectionInitializer();
                        } else {
                            memberInitializer.Value = parseExpression();
                        }
	                    memberInitializer.EndPosition = memberInitializer.Value.EndPosition;
                        objectInitializer.MemberInitializers.add(memberInitializer);
                    }
                    if (lexicalUnit != LexicalUnit.CloseBrace) {
                        throw error(ParseErrorId.CloseBraceExpected);
                    }
                   	objectInitializer.EndPosition = scanner.EndPosition;
                    nextLexicalUnit(false);
                    return objectInitializer;
                }
                this.restore(restorePoint);
            }
            var collectionInitializer = new CollectionInitializerExpressionNode();
            setScannerState(collectionInitializer);
            while (lexicalUnit != LexicalUnit.CloseBrace) {
                if (lexicalUnit == LexicalUnit.OpenBrace) {
                    nextLexicalUnit(true);
                    var values = new ArrayList<ExpressionNode>();
                    while (lexicalUnit != LexicalUnit.CloseBrace) {
                        values.add(parseExpression());
                        parseCommaOrCloseBrace();
                    }
                    nextLexicalUnit(false);
                    collectionInitializer.Values.add(values);
                } else {
                    var value = new ArrayList<ExpressionNode>();
                    value.add(parseExpression());
                    collectionInitializer.Values.add(value);
                }
                parseCommaOrCloseBrace();
            }
            collectionInitializer.EndPosition = scanner.EndPosition;
            nextLexicalUnit(false);
            return collectionInitializer;
        }
Example #2
0
 protected virtual TResult handleCollectionInitializer(CollectionInitializerExpressionNode initializer, TSource source, bool nested)
 {
     return(defaultHandler());
 }