Пример #1
0
        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;
        }
Пример #2
0
        private AnnotationSectionNode parseAnnotationSection() {
            var result = new AnnotationSectionNode();
            setScannerState(result);
            if (!isIdentifier(nextLexicalUnit(true))) {
                throw error(ParseErrorId.IdentifierExpected);
            }
            do {
                var attribute = new AnnotationCreationNode();
                setScannerState(attribute);
                attribute.Type = parseType(true);
                if (lexicalUnit == LexicalUnit.OpenParenthesis) {
                    if (nextLexicalUnit(true) != LexicalUnit.CloseParenthesis) {
                        var namedValue = false;
                        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();
                                setSavedScannerState(memberInitializer);
                                memberInitializer.NameOffset = sp;
                                memberInitializer.NameLength = len;
                                nextLexicalUnit(true);
                                memberInitializer.Value = parseAnnotationValue();
                                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();
                                    setSavedScannerState(memberInitializer);
                                    memberInitializer.NameOffset = sp;
                                    memberInitializer.NameLength = len;
                                    nextLexicalUnit(true);
                                    memberInitializer.Value = parseAnnotationValue();
	                                memberInitializer.EndPosition = memberInitializer.Value.EndPosition;
                                    objectInitializer.MemberInitializers.add(memberInitializer);
                                    objectInitializer.EndPosition = memberInitializer.EndPosition;
                                }
                                attribute.Initializer = objectInitializer;
                                namedValue = true;
                            }
                            if (!namedValue) {
                                this.restore(restorePoint);
                            }
                        }
                        if (!namedValue) {
                            attribute.Initializer = parseAnnotationValue();
                        }
                        if (lexicalUnit != LexicalUnit.CloseParenthesis) {
                            throw error(ParseErrorId.CloseParenthesisExpected);
                        }
                    }
					attribute.EndPosition = scanner.EndPosition;
                    nextLexicalUnit(true);
                } else {
					attribute.EndPosition = attribute.Type.EndPosition;
				}
                result.Annotations.add(attribute);
            } while (lexicalUnit == LexicalUnit.Comma);
            if (lexicalUnit != LexicalUnit.CloseBracket) {
                throw error(ParseErrorId.CloseBracketExpected);
            }
			result.EndPosition = scanner.EndPosition;
            nextLexicalUnit(false);
            return result;
        }
Пример #3
0
 protected virtual TResult handleObjectInitializer(ObjectInitializerExpressionNode initializer, TSource source, bool nested)
 {
     return(defaultHandler());
 }