DeIndent() публичный Метод

public DeIndent ( ) : void
Результат void
Пример #1
0
        void MakeTokenString(Token token, IndentingStringBuilder sb, Stack <string> endTags)
        {
            string tagName;
            string keyAttr;

            switch (token.Tokenkind)
            {
            case TokenType.StartScope:
            case TokenType.StartList:
            case TokenType.StartDict:
                sb.Indent();
                break;

            case TokenType.EndScope:
            case TokenType.EndList:
            case TokenType.EndDict:
                sb.DeIndent();
                sb.AppendFormatLine("</{0}>", endTags.Pop());
                break;

            case TokenType.SimpleFieldValue:
                tagName = TagName(token, out keyAttr);
                sb.AppendFormatLine("<{0}{1}>{2}</{0}>", tagName, keyAttr, Unquote(token.Value));
                break;

            case TokenType.SeenBeforeWithReference:
                tagName = TagName(token, out keyAttr);
                sb.AppendFormatLine("<{0}{1} ref='{2}'/>", tagName, keyAttr, token.ReferenceNo.Number);
                break;

            case TokenType.FieldnameWithTypeAndReference:
                var optionReferenceInfo = token.ReferenceNo != null
                      ? string.Format(" ref='{0}'", token.ReferenceNo.Number)
                      : "";

                var fieldType = OutputFormatterHelpers.MakeReadable(token.FieldType)
                                .Replace('<', '(')
                                .Replace('>', ')');
                tagName = TagName(token, out keyAttr);
                endTags.Push(tagName);
                sb.AppendFormatLine("<{0}{1} type='{2}'{3}>", tagName, keyAttr, fieldType, optionReferenceInfo);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #2
0
        void MakeTokenString(Token token, IndentingStringBuilder sb)
        {
            switch (token.Tokenkind)
            {
            case TokenType.StartScope:
            case TokenType.StartList:
            case TokenType.StartDict:
                sb.AppendFormatLine("{{");
                sb.Indent();
                break;

            case TokenType.EndScope:
            case TokenType.EndList:
            case TokenType.EndDict:
                sb.DeIndent();
                sb.AppendFormatLine("}}");
                break;

            case TokenType.SimpleFieldValue:
                sb.AppendFormatLine("{0}", MakeFieldValue(token, token.Value));
                break;

            case TokenType.SeenBeforeWithReference:
                sb.AppendFormatLine("{0}", MakeFieldValue(token, "-> " + token.ReferenceNo.Number));
                break;

            case TokenType.FieldnameWithTypeAndReference:
                var optionReferenceInfo = token.ReferenceNo == null
                      ? ""
                      : string.Format(", ref: {0}", token.ReferenceNo.Number);

                var fieldType = OutputFormatterHelpers.MakeReadable(token.FieldType);

                string value = string.Format("new {0}(){1}", fieldType, optionReferenceInfo);
                sb.AppendFormatLine("{0}", MakeFieldValue(token, value));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #3
0
        void MakeTokenString(Token token, IndentingStringBuilder sb)
        {
            switch (token.Tokenkind)
            {
            case TokenType.StartScope:
            case TokenType.StartList:
            case TokenType.StartDict:
                sb.AppendFormatLine("{{");
                sb.Indent();
                break;

            case TokenType.EndScope:
            case TokenType.EndList:
            case TokenType.EndDict:
                sb.DeIndent();
                sb.AppendFormatLine("}},");
                break;

            case TokenType.SimpleFieldValue:
                sb.AppendFormatLine("{0}", MakeFieldValue(token, token.Value));
                break;

            case TokenType.SeenBeforeWithReference:
                throw CreateCyclicalObjectGraphException();

            case TokenType.FieldnameWithTypeAndReference:
                if (token.ReferenceNo != null)
                {
                    throw CreateCyclicalObjectGraphException();
                }

                var fieldType = OutputFormatterHelpers.MakeReadable(token.FieldType);

                string value = string.Format("new {0}{1}", fieldType, token.FieldType.IsArray ? "" : "()");
                sb.AppendFormatLine("{0}", MakeFieldValue(token, value));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #4
0
        void MakeTokenString(Token token, IndentingStringBuilder sb)
        {
            switch (token.Tokenkind)
            {
                case TokenType.StartScope:
                case TokenType.StartList:
                case TokenType.StartDict:
                    sb.AppendFormatLine("{{");
                    sb.Indent();
                    break;

                case TokenType.EndScope:
                case TokenType.EndList:
                case TokenType.EndDict:
                    sb.DeIndent();
                    sb.AppendFormatLine("}}");
                    break;

                case TokenType.SimpleFieldValue:
                    sb.AppendFormatLine("{0}", MakeFieldValue(token, token.Value));
                    break;

                case TokenType.SeenBeforeWithReference:
                    sb.AppendFormatLine("{0}", MakeFieldValue(token, "-> " + token.ReferenceNo.Number));
                    break;

                case TokenType.FieldnameWithTypeAndReference:
                    var optionReferenceInfo = token.ReferenceNo == null
                      ? ""
                      : string.Format(", ref: {0}", token.ReferenceNo.Number);

                    var fieldType = OutputFormatterHelpers.MakeReadable(token.FieldType);

                    string value = string.Format("new {0}(){1}", fieldType, optionReferenceInfo);
                    sb.AppendFormatLine("{0}", MakeFieldValue(token, value));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Пример #5
0
        void MakeTokenString(Token token, IndentingStringBuilder sb, Stack<string> endTags)
        {
            string tagName;
            string keyAttr;
            switch (token.Tokenkind)
            {
                case TokenType.StartScope:
                case TokenType.StartList:
                case TokenType.StartDict:
                    sb.Indent();
                    break;

                case TokenType.EndScope:
                case TokenType.EndList:
                case TokenType.EndDict:
                    sb.DeIndent();
                    sb.AppendFormatLine("</{0}>", endTags.Pop());
                    break;

                case TokenType.SimpleFieldValue:
                    tagName = TagName(token, out keyAttr);
                    sb.AppendFormatLine("<{0}{1}>{2}</{0}>", tagName, keyAttr, Unquote(token.Value));
                    break;

                case TokenType.SeenBeforeWithReference:
                    tagName = TagName(token, out keyAttr);
                    sb.AppendFormatLine("<{0}{1} ref='{2}'/>", tagName, keyAttr, token.ReferenceNo.Number);
                    break;

                case TokenType.FieldnameWithTypeAndReference:
                    var optionReferenceInfo = token.ReferenceNo != null
                      ? string.Format(" ref='{0}'", token.ReferenceNo.Number)
                      : "";
                    var fieldType = OutputFormatterHelpers.MakeReadable(token.FieldType)
                        .Replace('<', '(')
                        .Replace('>', ')');
                    tagName = TagName(token, out keyAttr);
                    endTags.Push(tagName);
                    sb.AppendFormatLine("<{0}{1} type='{2}'{3}>", tagName, keyAttr, fieldType, optionReferenceInfo);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Пример #6
0
        int MakeStringFromToken(List<Token> tokens, int pos, Dictionary<Reference, string> referencePaths, IndentingStringBuilder sb)
        {
            var token = tokens[pos];
            TokenType? next = pos + 1 < tokens.Count ? tokens[pos + 1].Tokenkind : new TokenType?();
            int skip = 0;

            switch (token.Tokenkind)
            {
                case TokenType.StartScope:
                case TokenType.StartDict:
                    if (next == TokenType.EndScope || next == TokenType.EndDict)
                    {
                        sb.AppendFormatLine("{{}}{0}", OptionalComma(tokens, pos + 1));
                        ++skip;
                    }
                    else
                    {
                        sb.AppendFormatLine("{{");
                        sb.Indent();
                    }
                    break;

                case TokenType.EndScope:
                case TokenType.EndDict:
                    sb.DeIndent();
                    sb.AppendFormatLine("}}{0}", OptionalComma(tokens, pos));
                    break;

                case TokenType.StartList:
                    if (next == TokenType.EndList)
                    {
                        sb.AppendFormatLine("[]{0}", OptionalComma(tokens, pos + 1));
                        ++skip;
                    }
                    else
                    {
                        sb.AppendFormatLine("[");
                        sb.Indent();
                    }
                    break;

                case TokenType.EndList:
                    sb.DeIndent();
                    sb.AppendFormatLine("]{0}", OptionalComma(tokens, pos));
                    break;

                case TokenType.SimpleFieldValue:
                    sb.AppendFormatLine("{0}{1}", MakeFieldValue(token, token.Value),
                                        OptionalComma(tokens, pos));
                    break;

                case TokenType.SeenBeforeWithReference:
                    sb.AppendFormatLine("{0}{1}", MakeFieldValue(token, referencePaths[token.ReferenceNo]),
                                        OptionalComma(tokens, pos));
                    break;

                case TokenType.FieldnameWithTypeAndReference:
                    string value = MakeFieldValue(token, "");
                    sb.AppendFormat("{0}", value);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }

            return skip;
        }
Пример #7
0
        int MakeStringFromToken(List <Token> tokens, int pos, Dictionary <Reference, string> referencePaths, IndentingStringBuilder sb)
        {
            var       token = tokens[pos];
            TokenType?next  = pos + 1 < tokens.Count ? tokens[pos + 1].Tokenkind : new TokenType?();
            int       skip  = 0;

            switch (token.Tokenkind)
            {
            case TokenType.StartScope:
            case TokenType.StartDict:
                if (next == TokenType.EndScope || next == TokenType.EndDict)
                {
                    sb.AppendFormatLine("{{}}{0}", OptionalComma(tokens, pos + 1));
                    ++skip;
                }
                else
                {
                    sb.AppendFormatLine("{{");
                    sb.Indent();
                }
                break;

            case TokenType.EndScope:
            case TokenType.EndDict:
                sb.DeIndent();
                sb.AppendFormatLine("}}{0}", OptionalComma(tokens, pos));
                break;

            case TokenType.StartList:
                if (next == TokenType.EndList)
                {
                    sb.AppendFormatLine("[]{0}", OptionalComma(tokens, pos + 1));
                    ++skip;
                }
                else
                {
                    sb.AppendFormatLine("[");
                    sb.Indent();
                }
                break;

            case TokenType.EndList:
                sb.DeIndent();
                sb.AppendFormatLine("]{0}", OptionalComma(tokens, pos));
                break;

            case TokenType.SimpleFieldValue:
                sb.AppendFormatLine("{0}{1}", MakeFieldValue(token, token.Value),
                                    OptionalComma(tokens, pos));
                break;

            case TokenType.SeenBeforeWithReference:
                sb.AppendFormatLine("{0}{1}", MakeFieldValue(token, referencePaths[token.ReferenceNo]),
                                    OptionalComma(tokens, pos));
                break;

            case TokenType.FieldnameWithTypeAndReference:
                string value = MakeFieldValue(token, "");
                sb.AppendFormat("{0}", value);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(skip);
        }