/// <summary> /// Gets the name of the element. /// </summary> /// <returns>The name of the element.</returns> protected override string GetElementName() { for (Token token = this.FindFirstChildToken(); token != null; token = token.FindNextSiblingToken()) { if (token.Is(TokenType.Literal) || token.Is(TokenType.Type)) { return(token.Text); } } throw new SyntaxException(this.Document, this.LineNumber); }
/// <summary> /// Extracts a variable from the clause. /// </summary> /// <param name="firstToken">The first token of the variable.</param> /// <param name="allowTypelessVariable">Indicates whether to allow a variable with no type defined.</param> /// <param name="onlyTypelessVariable">Indicates whether to only get a typeless variable.</param> /// <returns>Returns the variable.</returns> protected static QueryClauseVariable ExtractQueryVariable(Token firstToken, bool allowTypelessVariable, bool onlyTypelessVariable) { Param.RequireNotNull(firstToken, "firstToken"); Param.Ignore(allowTypelessVariable); Param.Ignore(onlyTypelessVariable); if (onlyTypelessVariable || !firstToken.Is(TokenType.Type)) { // In this case there is no type, only an identifier. return(new QueryClauseVariable(null, firstToken.Text, firstToken.Location, firstToken.Generated)); } else { TypeToken type = (TypeToken)firstToken; // Attempt to get the identifier token coming after the type token. Token identifier = firstToken.FindNextSiblingToken(); if (identifier == null || identifier.TokenType != TokenType.Literal) { CsLanguageService.Debug.Assert(allowTypelessVariable, "The clause does not allow typeless variables. The parser should have thrown syntax exception already."); return(new QueryClauseVariable(null, type.Text, type.Location, type.Generated)); } else { // There is a type and an identifier. return(new QueryClauseVariable(type, identifier.Text, CodeUnit.JoinLocations(type, identifier), type.Generated || identifier.Generated)); } } }
/// <summary> /// Extracts a variable from the clause. /// </summary> /// <param name="firstToken">The first token of the variable.</param> /// <param name="allowTypelessVariable">Indicates whether to allow a variable with no type defined.</param> /// <param name="onlyTypelessVariable">Indicates whether to only get a typeless variable.</param> /// <returns>Returns the variable.</returns> protected static QueryClauseVariable ExtractQueryVariable(Token firstToken, bool allowTypelessVariable, bool onlyTypelessVariable) { Param.RequireNotNull(firstToken, "firstToken"); Param.Ignore(allowTypelessVariable); Param.Ignore(onlyTypelessVariable); if (onlyTypelessVariable || !firstToken.Is(TokenType.Type)) { // In this case there is no type, only an identifier. return new QueryClauseVariable(null, firstToken.Text, firstToken.Location, firstToken.Generated); } else { TypeToken type = (TypeToken)firstToken; // Attempt to get the identifier token coming after the type token. Token identifier = firstToken.FindNextSiblingToken(); if (identifier == null || identifier.TokenType != TokenType.Literal) { CsLanguageService.Debug.Assert(allowTypelessVariable, "The clause does not allow typeless variables. The parser should have thrown syntax exception already."); return new QueryClauseVariable(null, type.Text, type.Location, type.Generated); } else { // There is a type and an identifier. return new QueryClauseVariable(type, identifier.Text, CodeUnit.JoinLocations(type, identifier), type.Generated || identifier.Generated); } } }
/// <summary> /// Gets the name of the element. /// </summary> /// <returns>The name of the element.</returns> protected override string GetElementName() { CodeUnit start = this.Children.First; if (!this.ContainsModifier(TokenType.Implicit, TokenType.Explicit)) { // Get the return type. start = this.FindFirstChild <TypeToken>(); } if (start != null) { Token next = start.FindNextSiblingToken(); if (next != null) { if (next.Is(TokenType.Operator)) { // The next token is the operator name. Token operatorName = next.FindNextSiblingToken(); if (operatorName != null) { return("operator " + operatorName.Text); } } else { // This is a regular method. return(next.Text); } } } throw new SyntaxException(this.Document, this.LineNumber); }
/// <summary> /// Initializes the contents of the statement. /// </summary> private void Initialize() { Token token = this.FindFirstChildToken(); if (token == null) { throw new SyntaxException(this.Document, this.LineNumber); } else if (token.Is(TokenType.Break)) { this.type.Value = YieldStatement.Type.Break; this.returnValue.Value = null; } else if (token.Is(TokenType.Return)) { this.type.Value = YieldStatement.Type.Return; this.returnValue.Value = token.FindNextSiblingExpression(); } else { throw new SyntaxException(this.Document, this.LineNumber); } }