Пример #1
0
        private void AddSpansForStringToken(StringExpandableToken stringToken, int spanStart, List<ClassificationInfo> classificationInfo)
        {
            var startOffset = stringToken.Extent.StartOffset;
            foreach (var current in stringToken.NestedTokens)
            {
                ToClassificationInfo(stringToken, startOffset + spanStart, current.Extent.StartOffset - startOffset, classificationInfo);
                AddSpanForToken(current, spanStart, classificationInfo);
                startOffset = current.Extent.EndOffset;
            }

            ToClassificationInfo(stringToken, startOffset + spanStart, stringToken.Extent.EndOffset - startOffset, classificationInfo);
        }
Пример #2
0
 private List<ExpressionAst> ParseNestedExpressions(StringExpandableToken expandableStringToken)
 {
     ExpressionAst expressionAst;
     List<Token> tokens;
     List<ExpressionAst> expressionAsts = new List<ExpressionAst>();
     if (this._savingTokens)
     {
         tokens = new List<Token>();
     }
     else
     {
         tokens = null;
     }
     List<Token> tokens1 = tokens;
     foreach (Token nestedToken in expandableStringToken.NestedTokens)
     {
         VariableToken variableToken = nestedToken as VariableToken;
         if (variableToken == null)
         {
             TokenizerState tokenizerState = null;
             try
             {
                 tokenizerState = this._tokenizer.StartNestedScan((UnscannedSubExprToken)nestedToken);
                 expressionAst = this.PrimaryExpressionRule(true);
                 if (this._savingTokens)
                 {
                     tokens1.AddRange(this._tokenizer.TokenList);
                 }
             }
             finally
             {
                 this._ungotToken = null;
                 this._tokenizer.FinishNestedScan(tokenizerState);
             }
         }
         else
         {
             expressionAst = this.CheckUsingVariable(variableToken, false);
             if (this._savingTokens)
             {
                 tokens1.Add(variableToken);
             }
         }
         expressionAsts.Add(expressionAst);
     }
     if (this._savingTokens)
     {
         expandableStringToken.NestedTokens = new ReadOnlyCollection<Token>(tokens1);
     }
     return expressionAsts;
 }
Пример #3
0
        private ExpressionAst ExpandableStringRule(StringExpandableToken strToken)
        {
            //G  value:
            //G      literal

            ExpressionAst expr;
            // We need to scan the nested tokens even if there was some error. This is used by the tab completion: "pshome is $psh<tab>
            if (strToken.NestedTokens != null)
            {
                List<ExpressionAst> nestedExpressions = ParseNestedExpressions(strToken);
                expr = new ExpandableStringExpressionAst(strToken, strToken.Value, strToken.FormatString, nestedExpressions);
            }
            else
            {
                expr = new StringConstantExpressionAst(strToken);
            }
            return expr;
        }
Пример #4
0
 private ExpressionAst ExpandableStringRule(StringExpandableToken strToken)
 {
     ExpressionAst stringConstantExpressionAst;
     if (strToken.NestedTokens == null)
     {
         stringConstantExpressionAst = new StringConstantExpressionAst(strToken);
     }
     else
     {
         List<ExpressionAst> expressionAsts = this.ParseNestedExpressions(strToken);
         stringConstantExpressionAst = new ExpandableStringExpressionAst(strToken, strToken.Value, strToken.FormatString, expressionAsts);
     }
     return stringConstantExpressionAst;
 }
Пример #5
0
        private List<ExpressionAst> ParseNestedExpressions(StringExpandableToken expandableStringToken)
        {
            List<ExpressionAst> nestedExpressions = new List<ExpressionAst>();
            List<Token> newNestedTokens = _savingTokens ? new List<Token>() : null;
            foreach (var token in expandableStringToken.NestedTokens)
            {
                Diagnostics.Assert(!token.HasError || ErrorList.Any(), "No nested tokens should have unreported errors.");

                ExpressionAst exprAst;
                var varToken = token as VariableToken;

                if (varToken != null)
                {
                    exprAst = CheckUsingVariable(varToken, false);
                    if (_savingTokens) { newNestedTokens.Add(varToken); }
                }
                // Enable if we decide we still need to support
                //     "${}"  or "$var:"
                //else if (token.Kind == TokenKind.Unknown)
                //{
                //    //Diagnostics.Assert(token.Text.Equals("${}", StringComparison.OrdinalIgnoreCase),
                //    //    "The unknown token is only used in an expandable string when it's an empty variable name.");
                //    // TODO: Need strict-mode check at runtime.
                //    // TODO: in V2, "${}" expanded to '$', but "$var:" expanded to the empty string
                //    exprAst = new StringConstantExpressionAst(token.Extent, "$", StringConstantType.BareWord);
                //    if (_savingTokens) { newNestedTokens.Add(token); }
                //}
                else
                {
                    TokenizerState ts = null;
                    try
                    {
                        ts = _tokenizer.StartNestedScan((UnscannedSubExprToken)token);
                        exprAst = PrimaryExpressionRule(withMemberAccess: true);
                        if (_savingTokens) { newNestedTokens.AddRange(_tokenizer.TokenList); }
                    }
                    finally
                    {
                        // _ungotToken is probably <EOF>, but if there were errors, it could be something
                        // else.  Either way, we don't want it.
                        _ungotToken = null;
                        _tokenizer.FinishNestedScan(ts);
                    }
                }
                nestedExpressions.Add(exprAst);
            }

            if (_savingTokens) { expandableStringToken.NestedTokens = new ReadOnlyCollection<Token>(newNestedTokens); }
            return nestedExpressions;
        }