Esempio n. 1
0
        public string ToString(IndentType indentType)
        {
            var      stmt = this.GetStmt();
            IVisitor stringifier;

            if (indentType == IndentType.Compact)
            {
                stringifier = new CompactStringifier(144);
            }
            else if (indentType == IndentType.Beautiful)
            {
                stringifier = new BeautifulStringifier(
                    144
                    , 4
                    , BeautifulStringifier.KeywordCase.Upper
                    , BeautifulStringifier.JoinIndentType.A, true);
            }
            else
            {
                throw new InvalidEnumArgumentException("Undefined IndentType is used"
                                                       , (int)indentType
                                                       , typeof(IndentType));
            }

            stmt.Accept(stringifier);
            return(stringifier.ToString());
        }
Esempio n. 2
0
        private bool Directive_IfDefinedActual(IndentType type)
        {
            idToken token;
            int     skip;

            if ((token = ReadLine()) == null)
            {
                Error("#ifdef without name");
            }
            else if (token.Type != TokenType.Name)
            {
                UnreadSourceToken(token);
                Error("expected name after #ifdef, found '{0}'", token.ToString());
            }
            else
            {
                if (_defineDict.ContainsKey(token.ToString()) == true)
                {
                    skip = ((type == IndentType.IfDefined) == false) ? 1 : 0;
                }
                else
                {
                    skip = ((type == IndentType.IfDefined) == true) ? 1 : 0;
                }

                PushIndent(type, skip);

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
 public BoundIndentingRule(CompositeNodeType parentType, string leftTokenText, string rightTokenText, IndentType indentType = IndentType.Both)
 {
     myParentType     = parentType;
     myLeftTokenText  = leftTokenText;
     myRightTokenText = rightTokenText;
     myIndentType     = indentType;
 }
Esempio n. 4
0
 public void PopWhile(IndentType type)
 {
     while (Count > 0 && Peek() == type)
     {
         Pop();
     }
 }
Esempio n. 5
0
 public IndentXMLNodeDecorator(IXMLNodeDecorator dec, IndentType indent_type, int indent_num)
     : this()
 {
     this.dec_         = dec;
     this.indent_type_ = indent_type;
     this.indent_num_  = indent_num;
 }
Esempio n. 6
0
        private static string GetIndentString(IndentType type, int width)
        {
            char   character = type == IndentType.Tab ? '\t' : ' ';
            string indent    = new string(character, width);

            return(indent);
        }
Esempio n. 7
0
        /// <summary>
        /// Calculates indentation string given indent size in characters,
        /// type of indent (tabs or spaces) and size of the tab,
        /// </summary>
        /// <param name="size">Desired indent size in characters</param>
        /// <param name="indentType">Type of indent</param>
        /// <param name="tabSize">Tab size</param>
        /// <returns></returns>
        public static string GetIndentString(int size, IndentType indentType, int tabSize)
        {
            StringBuilder sb = new StringBuilder();

            size = Math.Max(size, 0);

            if (indentType == IndentType.Spaces)
            {
                sb.Append(' ', size);
            }
            else
            {
                if (tabSize > 0)
                {
                    int tabs   = size / tabSize;
                    int spaces = size % tabSize;

                    if (tabs > 0)
                    {
                        sb.Append('\t', tabs);
                    }

                    if (spaces > 0)
                    {
                        sb.Append(' ', spaces);
                    }
                }
            }

            return(sb.ToString());
        }
Esempio n. 8
0
 public BlockInfo(int lineStart, int lineTriggerWord, IndentType indentType, int statementNumber)
     : this()
 {
     LineStart       = lineStart;
     LineTriggerWord = lineTriggerWord;
     IndentType      = indentType;
     StatementNumber = statementNumber;
 }
Esempio n. 9
0
 /// <summary>
 /// Writes the line break.
 /// </summary>
 /// <param name="indentType">Type of the indent to use for the further lines.</param>
 protected void WriteLine(IndentType indentType)
 {
     writer.WriteLine();
     ChangeIndent(indentType);
     for (int i = 0, n = currentDepth * IndentSize; i < n; i++)
     {
         writer.Write(" ");
     }
 }
Esempio n. 10
0
        public IndentBuilder(IndentType indentType, int indentSize, int tabSize, string baseIndent) {
            IndentType = indentType;
            IndentSize = indentSize;
            TabSize = tabSize;

            ResetBaseIndent(baseIndent);

            SingleIndentString = GetIndentString(indentSize);
        }
Esempio n. 11
0
        public bool PopIf(IndentType type)
        {
            if (Count > 0 && Peek() == type)
            {
                Pop();
                return(true);
            }

            return(false);
        }
Esempio n. 12
0
        public IndentBuilder(IndentType indentType, int indentSize, int tabSize, string baseIndent)
        {
            IndentType = indentType;
            IndentSize = indentSize;
            TabSize    = tabSize;

            ResetBaseIndent(baseIndent);

            SingleIndentString = GetIndentString(indentSize);
        }
Esempio n. 13
0
        private void PushIndent(IndentType type, int skip)
        {
            ScriptIndentation indent = new ScriptIndentation();

            indent.Type   = type;
            indent.Script = _scriptStack.Peek();
            indent.Skip   = (skip != 0) ? 1 : 0;

            _skip += indent.Skip;
            _indentStack.Push(indent);
        }
Esempio n. 14
0
 /// <summary>
 /// Changes the indent.
 /// </summary>
 /// <param name="indentType">New type of the indent.</param>
 protected void ChangeIndent(IndentType indentType)
 {
     if (indentType == IndentType.Inner)
     {
         currentDepth++;
     }
     else if (indentType == IndentType.Outer)
     {
         currentDepth--;
         Debug.Assert(currentDepth >= 0);
     }
 }
        protected static IndentType GetIndentType(string indent)
        {
            IndentType indentType = IndentType.Space;

            if (indent.Length > 0)
            {
                char firstCharacter = indent[0];
                indentType = firstCharacter == '\t' ? IndentType.Tab : IndentType.Space;
            }

            return(indentType);
        }
Esempio n. 16
0
		int GetIndent(IndentType indentType)
		{
			switch (indentType) {
				case IndentType.Block:
					return options.IndentSize;
				case IndentType.Continuation:
					return options.ContinuationIndent;
				case IndentType.Label:
					return options.LabelIndent;
				default:
					throw new ArgumentOutOfRangeException();
			}
		}
Esempio n. 17
0
        private void WriteLine(string line, IndentType indentType = IndentType.None)
        {
            outStream.WriteLine(GetTabsForCurrentDepth() + line);
            switch (indentType)
            {
            case IndentType.Increase:
                currentDepth++;
                break;

            case IndentType.Decrease:
                currentDepth--;
                break;
            }
        }
Esempio n. 18
0
        public static IArtifacts Create(ArtifactsType artifactsType, string outputDir, string outputFile, IndentType indentType = IndentType.Space4)
        {
            switch (artifactsType)
            {
                case ArtifactsType.SingleFile:
                    return new SingleFileArtifacts(outputDir, outputFile);

                case ArtifactsType.MultipleFile:
                    return new MultipleFileArtifacts(outputDir);

                default:
                    return new ConsoleArtifacts();
            }
        }
        int GetIndent(IndentType indentType)
        {
            switch (indentType)
            {
            case IndentType.Block:
                return(options.IndentSize);

            case IndentType.Continuation:
                return(options.ContinuationIndent);

            case IndentType.Label:
                return(options.LabelIndent);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 20
0
        protected JavaScriptOutput(IndentType indentType = IndentType.Space4)
        {
            switch (indentType)
            {
            case IndentType.Space2:
                _indentString = new string(SPACE, 2);
                break;

            case IndentType.Space8:
                _indentString = new string(SPACE, 8);
                break;

            default:    //Note: Default 4 space.
                _indentString = new string(SPACE, 4);
                break;
            }
        }
Esempio n. 21
0
        protected JavaScriptOutput(IndentType indentType = IndentType.Space4)
        {
            switch (indentType)
            {
                case IndentType.Space2:
                    _indentString = new string(SPACE, 2);
                    break;

                case IndentType.Space8:
                    _indentString = new string(SPACE, 8);
                    break;

                default://Note: Default 4 space.
                    _indentString = new string(SPACE, 4);
                    break;
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Converts a indent type enum value to the code
        /// </summary>
        /// <param name="indentType">Indent type enum value</param>
        /// <returns>Indent type code</returns>
        private static string ConvertIndentTypeEnumValueToCode(IndentType indentType)
        {
            string code;

            switch (indentType)
            {
            case IndentType.Space:
                code = "space";
                break;

            case IndentType.Tab:
                code = "tab";
                break;

            default:
                throw new InvalidCastException(string.Format(CoreStrings.Common_EnumValueToCodeConversionFailed,
                                                             indentType.ToString(), typeof(IndentType)));
            }

            return(code);
        }
Esempio n. 23
0
        int GetIndent(IndentType indentType)
        {
            switch (indentType)
            {
            case IndentType.Block:
                return(options.GetOption(FormattingOptions.IndentationSize, LanguageNames.CSharp));

            case IndentType.DoubleBlock:
                return(options.GetOption(FormattingOptions.IndentationSize, LanguageNames.CSharp) * 2);

            case IndentType.Alignment:
            case IndentType.Continuation:
                return(options.GetOption(FormattingOptions.IndentationSize, LanguageNames.CSharp));

            case IndentType.Label:
                return(options.GetOption(FormattingOptions.IndentationSize, LanguageNames.CSharp));

            case IndentType.Empty:
                return(0);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 24
0
        private void PopIndent(out IndentType type, out int skip)
        {
            type = 0;
            skip = 0;

            if (_indentStack.Count == 0)
            {
                return;
            }

            ScriptIndentation indent = _indentStack.Peek();

            // must be an indent from the current script
            if (indent.Script != _scriptStack.Peek())
            {
                return;
            }

            type = indent.Type;
            skip = indent.Skip;

            _indentStack.Pop();
            _skip -= indent.Skip;
        }
Esempio n. 25
0
        private int GetIndent(IndentType indentType)
        {
            switch (indentType)
            {
            case IndentType.Block:
                return(options.IndentSize);

            case IndentType.DoubleBlock:
                return(options.IndentSize * 2);

            case IndentType.Alignment:
            case IndentType.Continuation:
                return(options.ContinuationIndent);

            case IndentType.Label:
                return(options.LabelIndent);

            case IndentType.Empty:
                return(0);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 26
0
 private void WriteLine(string line, IndentType indentType = IndentType.None)
 {
     outStream.WriteLine(GetTabsForCurrentDepth() + line);
      switch(indentType)
      {
     case IndentType.Increase:
        currentDepth++;
        break;
     case IndentType.Decrease:
        currentDepth--;
        break;
      }
 }
Esempio n. 27
0
 /// <summary>
 /// Add a block info on top of the block Stack
 /// </summary>
 /// <param name="indentType"></param>
 /// <param name="currentLine"></param>
 private void PushBlockInfoToStack(IndentType indentType, int currentLine)
 {
     _context.BlockStack.Push(new BlockInfo(_context.StatementFirstToken != null ? _context.StatementFirstToken.Line : 0, currentLine, indentType, _context.StatementCount));
 }
Esempio n. 28
0
		private bool Directive_IfDefinedActual(IndentType type)
		{
			idToken token;
			int skip;

			if((token = ReadLine()) == null)
			{
				Error("#ifdef without name");
			}
			else if(token.Type != TokenType.Name)
			{
				UnreadSourceToken(token);
				Error("expected name after #ifdef, found '{0}'", token.ToString());
			}
			else
			{
				if(_defineDict.ContainsKey(token.ToString()) == true)
				{
					skip = ((type == IndentType.IfDefined) == false) ? 1 : 0;
				}
				else
				{
					skip = ((type == IndentType.IfDefined) == true) ? 1 : 0;
				}

				PushIndent(type, skip);

				return true;
			}

			return false;
		}
Esempio n. 29
0
 public BlockInfo(int lineStart, int lineTriggerWord, IndentType indentType, int statementNumber)
     : this()
 {
     LineStart = lineStart;
     LineTriggerWord = lineTriggerWord;
     IndentType = indentType;
     StatementNumber = statementNumber;
 }
Esempio n. 30
0
		public bool PopIf(IndentType type)
		{
			if (Count > 0 && Peek() == type)
			{
				Pop();
				return true;
			}

			return false;
		}
Esempio n. 31
0
        private static string GetIndentString(IndentType type, int width)
        {
            char character = (type == IndentType.Tab) ? '\t' : ' ';
            string indent = new string(character, width);

            return indent;
        }
Esempio n. 32
0
 public JavaScriptConsoleOutput(IndentType indentType = IndentType.Space4) : base(indentType)
 {
 }
Esempio n. 33
0
		int GetIndent(IndentType indentType)
		{
			switch (indentType) {
				case IndentType.Block:
					return options.GetOption(FormattingOptions.IndentationSize, LanguageNames.CSharp);
				case IndentType.DoubleBlock:
					return options.GetOption(FormattingOptions.IndentationSize, LanguageNames.CSharp) * 2;
				case IndentType.Alignment:
				case IndentType.Continuation:
					return options.GetOption(FormattingOptions.IndentationSize, LanguageNames.CSharp);
				case IndentType.Label:
					return options.GetOption(FormattingOptions.IndentationSize, LanguageNames.CSharp);
				case IndentType.Empty:
					return 0;
				default:
					throw new ArgumentOutOfRangeException();
			}
		}
 public void Handle(SettingsChangedEvent message)
 {
     IndentType = settingsProvider.GetSettings <MarkPadSettings>().IndentType;
 }
Esempio n. 35
0
		private void PopIndent(out IndentType type, out int skip)
		{
			type = 0;
			skip = 0;

			if(_indentStack.Count == 0)
			{
				return;
			}

			ScriptIndentation indent = _indentStack.Peek();

			// must be an indent from the current script
			if(indent.Script != _scriptStack.Peek())
			{
				return;
			}

			type = indent.Type;
			skip = indent.Skip;

			_indentStack.Pop();
			_skip -= indent.Skip;
		}
Esempio n. 36
0
 public JavaScriptConsoleOutput(IndentType indentType = IndentType.Space4) : base(indentType)
 {
 }
Esempio n. 37
0
		private void PushIndent(IndentType type, int skip)
		{
			ScriptIndentation indent = new ScriptIndentation();
			indent.Type = type;
			indent.Script = _scriptStack.Peek();
			indent.Skip = (skip != 0) ? 1 : 0;

			_skip += indent.Skip;
			_indentStack.Push(indent);
		}
Esempio n. 38
0
 /// <summary>
 /// Add a block info on top of the block Stack
 /// </summary>
 /// <param name="indentType"></param>
 /// <param name="currentLine"></param>
 private void PushBlockInfoToStack(IndentType indentType, int currentLine)
 {
     _context.BlockStack.Push(new BlockInfo(_context.StatementFirstToken != null ? _context.StatementFirstToken.Line : 0, currentLine, indentType, _context.StatementCount));
 }
Esempio n. 39
0
 public IndentBuilder(IndentType indentType, int indentSize, int tabSize)
     : this(indentType, indentSize, tabSize, String.Empty)
 {
 }
Esempio n. 40
0
        // TODO 2 there is more going on here with dedent and number/string align
        private Indent GenerateIndent(
            Indent ind,
            IndentType newPart,
            Options options)
        {
            var queue = new List <IndentType>(ind.Queue);

            if (newPart.Type == "dedent")
            {
                queue.RemoveAt(queue.Count - 1);
            }
            else
            {
                queue.Add(newPart);
            }

            var value    = string.Empty;
            var length   = 0;
            var lastTabs = 0;

            var lastSpaces = 0;

            foreach (var part in queue)
            {
                switch (part.Type)
                {
                case "indent":
                    flush();
                    if (options.UseTabs)
                    {
                        addTabs(1);
                    }
                    else
                    {
                        addSpaces(options.TabWidth);
                    }
                    break;

                case "stringAlign":
                    flush();
                    value += part.Number;
                    // TODO 2 huh? length += part.n.length;
                    break;

                case "numberAlign":
                    lastTabs += 1;
                    // TODO 2 huh? lastSpaces += part.n;
                    break;

                default:
                    throw new Exception(part.Type);
                }
            }

            flushSpaces();

            void addTabs(int count)
            {
                value  += new string('\t', count);
                length += options.TabWidth * count;
            }

            void addSpaces(int count)
            {
                value  += new string(' ', count);
                length += count;
            }

            void flush()
            {
                if (options.UseTabs)
                {
                    flushTabs();
                }
                else
                {
                    flushSpaces();
                }
            }

            void flushTabs()
            {
                if (lastTabs > 0)
                {
                    addTabs(lastTabs);
                }

                resetLast();
            }

            void flushSpaces()
            {
                if (lastSpaces > 0)
                {
                    addSpaces(lastSpaces);
                }

                resetLast();
            }

            void resetLast()
            {
                lastTabs   = 0;
                lastSpaces = 0;
            }

            // TODO 2 in prettier this has a ...ind
            return(new Indent(value, length, queue));
        }
Esempio n. 41
0
        /// <summary>
        /// JSONを見易く整形する
        /// </summary>
        /// <param name="json">json.</param>
        /// <param name="indentType">indentType.</param>
        /// <param name="indentSize">indentSize.</param>
        /// <returns>見易く整形したJSON</returns>
        public static string ToPrettyPrint(string json, IndentType indentType, int indentSize = 4)
        {
            json = ToMinifyPrint(json);


            var stringBuilder = new StringBuilder();

            AppendType appendType = AppendType.None;
            int        i          = 0;
            int        quoteCount = 0;
            int        indent     = 0;
            int        position   = 0;
            int        lastIndex  = 0;

            while (i < json.Length)
            {
                if (i > 0 && json[i - 1] != '\\' && json[i] == '"')
                {
                    ++quoteCount;
                }

                if (quoteCount % 2 == 0)
                {
                    switch (json[i])
                    {
                    case '{':
                        ++indent;
                        position   = 1;
                        appendType = AppendType.AppendLine;
                        break;

                    case '[':
                        position = 1;
                        if (json[i + 1] == ']')
                        {
                            appendType = AppendType.Append;
                        }
                        else
                        {
                            ++indent;
                            appendType = AppendType.AppendLine;
                        }
                        break;

                    case '}':
                    case ']':
                        --indent;
                        position   = 0;
                        appendType = AppendType.AppendLine;
                        break;

                    case ',':
                        position   = 1;
                        appendType = AppendType.AppendLine;
                        break;

                    case ':':
                        position   = 1;
                        appendType = AppendType.AppendSpace;
                        break;
                    }

                    switch (appendType)
                    {
                    case AppendType.None:
                        break;

                    case AppendType.Append:
                        stringBuilder.Append(json.Substring(lastIndex, i + position - lastIndex));
                        lastIndex = i + position;
                        i         = lastIndex;
                        break;

                    case AppendType.AppendLine:
                        stringBuilder.AppendLine(json.Substring(lastIndex, i + position - lastIndex));

                        switch (indentType)
                        {
                        case IndentType.Space:
                            stringBuilder.Append(new string(' ', indent * indentSize));
                            break;

                        case IndentType.Tab:
                            stringBuilder.Append(new string('\t', indent));
                            break;

                        default:
                            throw new ArgumentOutOfRangeException("indentType", indentType, null);
                        }

                        lastIndex = i + position;
                        break;

                    case AppendType.AppendSpace:
                        stringBuilder.Append(json.Substring(lastIndex, i + position - lastIndex)).Append(' ');
                        lastIndex = i + position;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    appendType = AppendType.None;
                }

                ++i;
            }

            stringBuilder.Append(json.Substring(lastIndex));
            return(stringBuilder.ToString());
        }
Esempio n. 42
0
		public void PopWhile(IndentType type)
		{
			while (Count > 0 && Peek() == type)
			{
				Pop();
			}
		}
Esempio n. 43
0
		public void Push(IndentType type)
		{
			indentStack.Push(type);
			curIndent += GetIndent(type);
			Update();
		}
Esempio n. 44
0
 public void Push(IndentType type)
 {
     indentStack.Push(type);
     curIndent += GetIndent(type);
     Update();
 }
Esempio n. 45
0
        /// <summary>
        /// Calculates indentation string given indent size in characters, 
        /// type of indent (tabs or spaces) and size of the tab,
        /// </summary>
        /// <param name="size">Desired indent size in characters</param>
        /// <param name="indentType">Type of indent</param>
        /// <param name="tabSize">Tab size</param>
        /// <returns></returns>
        public static string GetIndentString(int size, IndentType indentType, int tabSize) {
            StringBuilder sb = new StringBuilder();
            size = Math.Max(size, 0);

            if (indentType == IndentType.Spaces) {
                sb.Append(' ', size);
            } else {
                if (tabSize > 0) {
                    int tabs = size / tabSize;
                    int spaces = size % tabSize;

                    if (tabs > 0) {
                        sb.Append('\t', tabs);
                    }

                    if (spaces > 0) {
                        sb.Append(' ', spaces);
                    }
                }
            }

            return sb.ToString();
        }
        public static string Format(string str)
        {
            List <Token> originalTokens = Tokenize(str);

            List <Token> tokens = originalTokens
                                  .Where(token => token.Type != TokenType.Whitespace)
                                  .ToList();

            bool increaseSpecialIndent = false;
            bool increaseBlockIndent   = false;
            int  indentLevel           = 0;

            bool   newline           = false;
            string result            = string.Empty;
            bool   addedNewline      = false;
            bool   inlineParentheses = false;
            bool   inlineIndented    = false;
            int    inlineCount       = 0;
            bool   clauseLimit       = false;

            var indentTypes = new Stack <IndentType>();

            for (int i = 0; i < tokens.Count; i++)
            {
                Token  token       = tokens[i];
                string highlighted = token.Value;

                if (increaseSpecialIndent)
                {
                    indentLevel++;
                    increaseSpecialIndent = false;
                    indentTypes.Push(IndentType.Special);
                }

                if (increaseBlockIndent)
                {
                    indentLevel++;
                    increaseBlockIndent = false;
                    indentTypes.Push(IndentType.Block);
                }

                if (newline)
                {
                    result      += Environment.NewLine + new string(Tab, indentLevel);
                    newline      = false;
                    addedNewline = true;
                }
                else
                {
                    addedNewline = false;
                }

                if (token.Type == TokenType.Comment || token.Type == TokenType.BlockComment)
                {
                    if (token.Type == TokenType.BlockComment)
                    {
                        var indent = new string(Tab, indentLevel);
                        result      = Environment.NewLine + indent;
                        highlighted = highlighted.Replace(Environment.NewLine, Environment.NewLine + indent);
                    }

                    result += highlighted;
                    newline = true;
                    continue;
                }

                if (inlineParentheses)
                {
                    if (token.Value == ")")
                    {
                        result = result.TrimEnd(' ');

                        if (inlineIndented)
                        {
                            indentTypes.Pop();
                            indentLevel--;
                            result += Environment.NewLine + new string(Tab, indentLevel);
                        }

                        inlineParentheses = false;

                        result += highlighted + ' ';
                        continue;
                    }

                    if (token.Value == ",")
                    {
                        if (inlineCount >= 30)
                        {
                            inlineCount = 0;
                            newline     = true;
                        }
                    }

                    inlineCount += token.Value.Length;
                }

                if (token.Value == "(")
                {
                    int length = 0;
                    for (int j = 1; j < 250; j++)
                    {
                        if (i + j >= tokens.Count)
                        {
                            break;
                        }

                        Token next = tokens[i + j];

                        if (next.Value == ")")
                        {
                            inlineParentheses = true;
                            inlineCount       = 0;
                            inlineIndented    = false;
                            break;
                        }

                        if (next.Value == ";" || next.Value == "(")
                        {
                            break;
                        }

                        if (next.Type == TokenType.ReservedTopLevel || next.Type == TokenType.ReservedNewline || next.Type == TokenType.Comment || next.Type == TokenType.BlockComment)
                        {
                            break;
                        }
                        length += next.Value.Length;
                    }

                    if (i < originalTokens.Count && originalTokens[i].Type == TokenType.Whitespace)
                    {
                        result = result.TrimEnd(' ');
                    }

                    if (!inlineParentheses)
                    {
                        increaseBlockIndent = true;
                        newline             = true;
                    }
                }
                else if (token.Value == ")")
                {
                    result = result.TrimEnd(' ');
                    indentLevel--;

                    while (indentTypes.Count > 0)
                    {
                        IndentType type = indentTypes.Pop();
                        if (type == IndentType.Special)
                        {
                            indentLevel--;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (indentLevel < 0)
                    {
                        continue;
                    }

                    if (!addedNewline)
                    {
                        result += Environment.NewLine + new string(Tab, indentLevel);
                    }
                }
                else if (token.Type == TokenType.ReservedTopLevel)
                {
                    increaseSpecialIndent = true;

                    if (indentTypes.Count > 0 && indentTypes.Peek() == IndentType.Special)
                    {
                        indentLevel--;
                        indentTypes.Pop();
                    }

                    newline = true;

                    if (!addedNewline)
                    {
                        result += Environment.NewLine + new string(Tab, indentLevel);
                    }
                    else
                    {
                        result = result.TrimEnd() + new string(Tab, indentLevel);
                    }

                    if (!token.Value.Contains(' ') || !token.Value.Contains('\n') || !token.Value.Contains(Tab))
                    {
                        highlighted = Regex.Replace(highlighted, @"\s+", " ");
                    }

                    if (token.Value == "LIMIT" && !inlineParentheses)
                    {
                        clauseLimit = true;
                    }
                }
                else if (clauseLimit && token.Value != "," && token.Type != TokenType.Number && token.Type != TokenType.Whitespace)
                {
                    clauseLimit = false;
                }
                else if (token.Value == "," && !inlineParentheses)
                {
                    if (clauseLimit)
                    {
                        newline     = false;
                        clauseLimit = false;
                    }
                    else
                    {
                        newline = true;
                    }
                }
                else if (token.Type == TokenType.ReservedNewline)
                {
                    if (!addedNewline)
                    {
                        result += Environment.NewLine + new string(Tab, indentLevel);
                    }

                    if (!token.Value.Contains(' ') || !token.Value.Contains('\n') || !token.Value.Contains(Tab))
                    {
                        highlighted = Regex.Replace(highlighted, @"\s+", " ");
                    }
                }
                else if (token.Type == TokenType.Boundary)
                {
                    if (i - 1 >= 0 && tokens[i - 1].Type == TokenType.Boundary)
                    {
                        if (i < originalTokens.Count && originalTokens[i - 1].Type != TokenType.Whitespace)
                        {
                            result = result.TrimEnd(' ');
                        }
                    }
                }

                if (token.Value == "." || token.Value == "," || token.Value == ";")
                {
                    result = result.TrimEnd(' ');
                }

                result += highlighted + ' ';

                if (token.Value == "(" || token.Value == ".")
                {
                    result = result.TrimEnd(' ');
                }

                if (token.Value == "-" && i + 1 < tokens.Count && tokens[i + 1].Type == TokenType.Number && i - 1 >= 0)
                {
                    TokenType prev = tokens[i - 1].Type;

                    if (prev != TokenType.Quote && prev != TokenType.BacktickQuote && prev != TokenType.Word && prev != TokenType.Number)
                    {
                        result = result.TrimEnd(' ');
                    }
                }
            }

            return(result);
        }
Esempio n. 47
0
 public IndentBuilder(IndentType indentType, int indentSize, int tabSize)
     : this(indentType, indentSize, tabSize, String.Empty) {
 }
Esempio n. 48
0
 public IndentDecorator(TextBlock decoratedTextBlock, IndentType indent) : base(decoratedTextBlock)
 {
     Indent = indent;
 }