Пример #1
0
 private IEnumerable<Expression> ParseCollectionElementValueList(SourceLocationBuilder slb, TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   List<Expression> elementValues = new List<Expression>();
   while (this.currentToken != Token.RightBrace && this.currentToken != Token.EndOfFile) {
     Expression elementValue;
     if (this.currentToken == Token.LeftBrace) {
       IEnumerable<Expression> nestedElementValues = Expression.EmptyCollection;
       IEnumerable<NamedArgument> nestedNamedArguments = NamedArgument.EmptyCollection;
       //^ assume this.currentToken == Token.LeftBrace;
       this.ParseElementValuesOrNamedArguments(ref nestedElementValues, ref nestedNamedArguments, slb, followers);
       if (nestedElementValues != Expression.EmptyCollection)
         elementValue = new PopulateCollection(null, nestedElementValues, slb);
       else if (nestedNamedArguments != NamedArgument.EmptyCollection)
         elementValue = new InitializeObject(null, nestedNamedArguments, slb);
       else {
         this.HandleError(Error.SyntaxError); //TODO: better error
         continue;
       }
     } else
       elementValue = this.ParseExpression(followers|Token.Comma);
     elementValues.Add(elementValue);
     if (this.currentToken != Token.Comma) break;
     this.GetNextToken();
   }
   elementValues.TrimExcess();
   IEnumerable<Expression> result = elementValues.AsReadOnly();
   this.SkipTo(followers);
   return result;
 }
Пример #2
0
 private IEnumerable<NamedArgument> ParseNamedArgumentList(SourceLocationBuilder slb, TokenSet followers)
   //^ requires Parser.IdentifierOrNonReservedKeyword[this.currentToken];
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   List<NamedArgument> namedArguments = new List<NamedArgument>();
   while (Parser.IdentifierOrNonReservedKeyword[this.currentToken]) {
     SimpleName argumentName = this.ParseSimpleName(followers|Token.Comma);
     this.Skip(Token.Assign);
     Expression argumentValue;
     if (this.currentToken == Token.LeftBrace) {
       IEnumerable<Expression> nestedElementValues = Expression.EmptyCollection;
       IEnumerable<NamedArgument> nestedNamedArguments = NamedArgument.EmptyCollection;
       //^ assume this.currentToken == Token.LeftBrace;
       this.ParseElementValuesOrNamedArguments(ref nestedElementValues, ref nestedNamedArguments, slb, followers);
       if (nestedElementValues != Expression.EmptyCollection)
         argumentValue = new PopulateCollection(null, nestedElementValues, slb);
       else if (nestedNamedArguments != NamedArgument.EmptyCollection)
         argumentValue = new InitializeObject(null, nestedNamedArguments, slb);
       else {
         this.HandleError(Error.SyntaxError); //TODO: better error
         continue;
       }
     } else
       argumentValue = this.ParseExpression(followers|Token.Comma);
     namedArguments.Add(new NamedArgument(argumentName, argumentValue, slb));
     if (this.currentToken != Token.Comma) break;
     this.GetNextToken();
   }
   namedArguments.TrimExcess();
   IEnumerable<NamedArgument> result = namedArguments.AsReadOnly();
   this.SkipTo(followers);
   return result;
 }