protected virtual int ParseVersion([NotNull] ICompileContext context, [NotNull] IDatabase database, [NotNull] ITextSnapshot textSnapshot, [NotNull] LanguageVersionBuilder languageVersionBuilder, [NotNull, ItemNotNull] string[] lines, int lineNumber)
        {
            for (var n = lineNumber; n < lines.Length; n++)
            {
                var line = lines[n];
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                var i = line.IndexOf(':');
                if (i < 0)
                {
                    return(n - 1);
                }

                var name  = line.Left(i).Trim();
                var value = line.Mid(i + 1).Trim();

                switch (name)
                {
                case "language":
                    languageVersionBuilder.Language         = database.GetLanguage(value);
                    languageVersionBuilder.LanguageTextNode = Factory.TextNode(textSnapshot, "language", value, GetTextSpan(n, 0, line.Length));
                    break;

                case "version":
                    if (Version.TryParse(value, out Version version))
                    {
                        languageVersionBuilder.Version         = version;
                        languageVersionBuilder.VersionTextNode = Factory.TextNode(textSnapshot, "version", value, GetTextSpan(n, 0, line.Length));
                    }
                    break;

                case "revision": break;
                }
            }

            return(lines.Length);
        }
        protected virtual int ParseField([NotNull] ICompileContext context, [NotNull] ITextSnapshot textSnapshot, [NotNull] ItemBuilder itemBuilder, [NotNull] LanguageVersionBuilder languageVersionBuilder, [NotNull, ItemNotNull] string[] lines, int lineNumber)
        {
            var textNode = Factory.TextNode(textSnapshot, string.Empty, string.Empty, GetTextSpan(lineNumber, 0, 0));

            var fieldBuilder = new FieldBuilder(Factory).With(itemBuilder, textNode);

            itemBuilder.Fields.Add(fieldBuilder);

            fieldBuilder.Language         = languageVersionBuilder.Language;
            fieldBuilder.LanguageTextNode = languageVersionBuilder.LanguageTextNode;

            fieldBuilder.Version         = languageVersionBuilder.Version;
            fieldBuilder.VersionTextNode = languageVersionBuilder.VersionTextNode;

            var lineLength = 0;

            int n;

            for (n = lineNumber; n < lines.Length; n++)
            {
                var line = lines[n];
                lineLength += line.Length;

                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                var i = line.IndexOf(':');
                if (i < 0)
                {
                    break;
                }

                var name  = line.Left(i).Trim();
                var value = line.Mid(i + 1).Trim();

                switch (name)
                {
                case "field":
                    fieldBuilder.FieldId         = value;
                    fieldBuilder.FieldIdTextNode = Factory.TextNode(textSnapshot, "field", value, GetTextSpan(lineNumber, 0, lineLength));
                    break;

                case "name":
                    fieldBuilder.FieldName         = value;
                    fieldBuilder.FieldNameTextNode = Factory.TextNode(textSnapshot, "name", value, GetTextSpan(lineNumber, 0, lineLength));
                    break;

                case "key": break;
                }

                if (name == "content-length")
                {
                    var contentLength = int.Parse(value);
                    n = ParseFieldValue(context, textSnapshot, lines, fieldBuilder, n + 2, contentLength, ref lineLength);
                    break;
                }
            }

            return(n);
        }
        protected virtual int ParseItem([NotNull] ICompileContext context, [NotNull] ITextSnapshot textSnapshot, [NotNull] ItemBuilder itemBuilder, [NotNull, ItemNotNull] string[] lines)
        {
            var languageVersionBuilder = new LanguageVersionBuilder();

            for (var n = 0; n < lines.Length; n++)
            {
                var line = lines[n];
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                if (line == "----field----")
                {
                    n = ParseField(context, textSnapshot, itemBuilder, languageVersionBuilder, lines, n + 1);
                    continue;
                }

                if (line == "----version----")
                {
                    n = ParseVersion(context, context.Project.GetDatabase(itemBuilder.DatabaseName), textSnapshot, languageVersionBuilder, lines, n + 1);
                    continue;
                }

                if (line == "----item----")
                {
                    continue;
                }

                var i = line.IndexOf(':');
                if (i < 0)
                {
                    return(n);
                }

                var name  = line.Left(i).Trim();
                var value = line.Mid(i + 1).Trim();

                switch (name)
                {
                case "id":
                    itemBuilder.Guid = value;
                    break;

                case "database":
                    itemBuilder.DatabaseName = value;
                    break;

                case "path":
                    itemBuilder.ItemIdOrPath = value;
                    break;

                case "parent": break;

                case "name":
                    itemBuilder.ItemName         = value;
                    itemBuilder.ItemNameTextNode = Factory.TextNode(textSnapshot, "name", value, GetTextSpan(n, 0, line.Length));
                    break;

                case "master": break;

                case "template":
                    itemBuilder.TemplateIdOrPath         = value;
                    itemBuilder.TemplateIdOrPathTextNode = Factory.TextNode(textSnapshot, "template", value, GetTextSpan(n, 0, line.Length));
                    break;

                case "templatekey": break;

                case "version": break;
                }
            }

            return(lines.Length);
        }