// // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. // using System.Text; using System.Collections.Generic; namespace Microsoft.SqlTools.ServiceLayer.BatchParser { internal class TextBlock { private readonly Parser parser; private readonly IEnumerable tokens; /// /// Constructor for the TextBlock class /// public TextBlock(Parser parser, Token token) : this(parser, new[] { token }) { } /// /// Constructor for the TextBlock class /// public TextBlock(Parser parser, IEnumerable tokens) { this.parser = parser; this.tokens = tokens; } /// /// Get text from TextBlock /// public void GetText(bool resolveVariables, out string text, out LineInfo lineInfo) { StringBuilder sb = new StringBuilder(); List variableRefs = null; if (resolveVariables == false) { foreach (Token token in tokens) { sb.Append(token.Text); } } else { variableRefs = new List(); foreach (Token token in tokens) { if (token.TokenType == LexerTokenType.Text) { sb.Append(parser.ResolveVariables(token, sb.Length, variableRefs)); } else { // comments and whitespaces do not need variable expansion sb.Append(token.Text); } } } lineInfo = new LineInfo(tokens, variableRefs); text = sb.ToString(); } } }