Inheritance: Microsoft.JScript.Exp
Example #1
0
      //---------------------------------------------------------------------------------------
      // ParseIdentifierInitializer
      //
      //  Does the real work of parsing a single variable declaration.
      //  inToken is JSToken.In whenever the potential expression that initialize a variable
      //  cannot contain an 'in', as in the for statement. inToken is JSToken.None otherwise
      //---------------------------------------------------------------------------------------
      private AST ParseIdentifierInitializer(JSToken inToken,
                                                              FieldAttributes visibility,
                                                              CustomAttributeList customAttributes,
                                                              JSToken kind){
        Lookup id = null;
        TypeExpression typeExpr = null;
        AST assignmentExpr = null;
        RecoveryTokenException except = null;

        GetNextToken();
        if (JSToken.Identifier != this.currentToken.token){
          String identifier = JSKeyword.CanBeIdentifier(this.currentToken.token);
          if (null != identifier){
            ForceReportInfo(JSError.KeywordUsedAsIdentifier);
            id = new Lookup(identifier, this.currentToken.Clone());
          }else{
            // make up an identifier and keep going; life goes on...
            ReportError(JSError.NoIdentifier);
            id = new Lookup("#_Missing Identifier_#" + s_cDummyName++, CurrentPositionContext());
          }
        }else
          id = new Lookup(this.scanner.GetIdentifier(), this.currentToken.Clone());
        GetNextToken();
        Context context = id.context.Clone();

        this.noSkipTokenSet.Add(NoSkipTokenSet.s_VariableDeclNoSkipTokenSet);
        try{
          if (JSToken.Colon == this.currentToken.token){
            try{
              typeExpr = ParseTypeExpression();
            }catch(RecoveryTokenException exc){
              typeExpr = (TypeExpression)exc._partiallyComputedNode;
              throw exc;
            }finally{
              if (null != typeExpr)
                context.UpdateWith(typeExpr.context);
            }
          }
              
          if (JSToken.Assign == this.currentToken.token || JSToken.Equal == this.currentToken.token){
            if (JSToken.Equal == this.currentToken.token)
              ReportError(JSError.NoEqual, true);
            GetNextToken();
            try{
              assignmentExpr = ParseExpression(true, inToken);
            }catch(RecoveryTokenException exc){
              assignmentExpr = exc._partiallyComputedNode;
              throw exc;
            }finally{
              if (null != assignmentExpr)
                context.UpdateWith(assignmentExpr.context);
            }
          }
        }catch(RecoveryTokenException exc){
          // If the exception is in the vardecl no-skip set then we successfully
          // recovered to the end of the declaration and can just return
          // normally.  Otherwise we re-throw after constructing the partial result.  
          if (IndexOfToken(NoSkipTokenSet.s_VariableDeclNoSkipTokenSet, exc) == -1)
            except = exc;
        }finally{
          this.noSkipTokenSet.Remove(NoSkipTokenSet.s_VariableDeclNoSkipTokenSet);
        }

        AST result = null;
        if (JSToken.Var == kind)
          result = new VariableDeclaration(context, id, typeExpr, assignmentExpr, visibility, customAttributes);
        else{
          if (assignmentExpr == null)
            ForceReportInfo(JSError.NoEqual);
          result = new Constant(context, id, typeExpr, assignmentExpr, visibility, customAttributes);
        }
        if (customAttributes != null)
          customAttributes.SetTarget(result);
        if (null != except){
          except._partiallyComputedNode = result;
          throw except;
        }
        return result;
      }
 private AST ParseIdentifierInitializer(JSToken inToken, FieldAttributes visibility, CustomAttributeList customAttributes, JSToken kind)
 {
     Lookup identifier = null;
     TypeExpression type = null;
     AST initializer = null;
     RecoveryTokenException exception = null;
     this.GetNextToken();
     if (JSToken.Identifier != this.currentToken.token)
     {
         string name = JSKeyword.CanBeIdentifier(this.currentToken.token);
         if (name != null)
         {
             this.ForceReportInfo(JSError.KeywordUsedAsIdentifier);
             identifier = new Lookup(name, this.currentToken.Clone());
         }
         else
         {
             this.ReportError(JSError.NoIdentifier);
             identifier = new Lookup("#_Missing Identifier_#" + s_cDummyName++, this.CurrentPositionContext());
         }
     }
     else
     {
         identifier = new Lookup(this.scanner.GetIdentifier(), this.currentToken.Clone());
     }
     this.GetNextToken();
     Context context = identifier.context.Clone();
     this.noSkipTokenSet.Add(NoSkipTokenSet.s_VariableDeclNoSkipTokenSet);
     try
     {
         if (JSToken.Colon == this.currentToken.token)
         {
             try
             {
                 type = this.ParseTypeExpression();
             }
             catch (RecoveryTokenException exception2)
             {
                 type = (TypeExpression) exception2._partiallyComputedNode;
                 throw exception2;
             }
             finally
             {
                 if (type != null)
                 {
                     context.UpdateWith(type.context);
                 }
             }
         }
         if ((JSToken.Assign == this.currentToken.token) || (JSToken.Equal == this.currentToken.token))
         {
             if (JSToken.Equal == this.currentToken.token)
             {
                 this.ReportError(JSError.NoEqual, true);
             }
             this.GetNextToken();
             try
             {
                 initializer = this.ParseExpression(true, inToken);
             }
             catch (RecoveryTokenException exception3)
             {
                 initializer = exception3._partiallyComputedNode;
                 throw exception3;
             }
             finally
             {
                 if (initializer != null)
                 {
                     context.UpdateWith(initializer.context);
                 }
             }
         }
     }
     catch (RecoveryTokenException exception4)
     {
         if (this.IndexOfToken(NoSkipTokenSet.s_VariableDeclNoSkipTokenSet, exception4) == -1)
         {
             exception = exception4;
         }
     }
     finally
     {
         this.noSkipTokenSet.Remove(NoSkipTokenSet.s_VariableDeclNoSkipTokenSet);
     }
     AST target = null;
     if (JSToken.Var == kind)
     {
         target = new VariableDeclaration(context, identifier, type, initializer, visibility, customAttributes);
     }
     else
     {
         if (initializer == null)
         {
             this.ForceReportInfo(JSError.NoEqual);
         }
         target = new Constant(context, identifier, type, initializer, visibility, customAttributes);
     }
     if (customAttributes != null)
     {
         customAttributes.SetTarget(target);
     }
     if (exception != null)
     {
         exception._partiallyComputedNode = target;
         throw exception;
     }
     return target;
 }