public override void Parse(ParseContext <JsonTokenType> context) { switch (context.CurrentToken.Type) { case JsonTokenType.Property: case JsonTokenType.PropertyQuoted: if (expectingSeparator) { throw new InvalidDataException("Unexpected token: " + context.LookaheadToken + ", after: " + context.CurrentToken); } var key = context.CurrentToken.Value; if (context.CurrentToken.Type == JsonTokenType.PropertyQuoted) { key = JsonUtil.UnescapeString(key); } switch (context.LookaheadToken.Type) { case JsonTokenType.ObjectStart: case JsonTokenType.ArrayStart: context.PushParser(new AnyParser(r => result.Add(key, r))); break; case JsonTokenType.Word: case JsonTokenType.WordQuoted: context.PushParser(new ValueParser(r => result.Add(key, r))); break; default: throw new InvalidDataException("Unexpected token: " + context.LookaheadToken + ", after: " + context.CurrentToken); } expectingSeparator = true; context.ConsumeToken(); return; case JsonTokenType.ValueSeparator: expectingSeparator = false; context.ConsumeToken(); return; case JsonTokenType.ObjectEnd: context.ConsumeToken(); context.PopParser(); return; } throw new InvalidDataException("Unexpected token: " + context.CurrentToken); }
public override void Parse(ParseContext <YamlTokenType> context) { if (CheckIndent(context)) { return; } switch (context.LookaheadToken.Type) { case YamlTokenType.ArrayIndicator: case YamlTokenType.Property: case YamlTokenType.PropertyQuoted: throw new InvalidDataException("Unexpected token: " + context.LookaheadToken + ", after: " + context.CurrentToken); } switch (context.CurrentToken.Type) { case YamlTokenType.Property: case YamlTokenType.PropertyQuoted: var key = context.CurrentToken.Value; if (context.CurrentToken.Type == YamlTokenType.PropertyQuoted) { key = YamlUtil.UnescapeString(key); } switch (context.LookaheadToken.Type) { case YamlTokenType.Word: case YamlTokenType.WordQuoted: context.PushParser(new ValueParser(r => result.Add(key, r))); break; case YamlTokenType.EndLine: context.PushParser(new EmptyProperyParser(r => result.Add(key, r), context.IndentLevel + 1)); break; default: throw new InvalidDataException("Unexpected token: " + context.LookaheadToken + ", after: " + context.CurrentToken); } context.ConsumeToken(); return; } throw new InvalidDataException("Unexpected token: " + context.CurrentToken); }
private void saveText(string path) { if (disposedValue) { throw new ObjectDisposedException(nameof(Project)); } // Create the opener file if (!File.Exists(path)) { File.WriteAllText(path, "# This file is only used to open the project\n# Project data is contained in the .sbrew folder"); } var projectDirectory = Path.GetDirectoryName(path); var gitIgnorePath = Path.Combine(projectDirectory, ".gitignore"); if (!File.Exists(gitIgnorePath)) { File.WriteAllText(gitIgnorePath, ".sbrew/user.yaml\n.sbrew.tmp\n.sbrew.bak\n.cache\n.vs"); } var targetDirectory = Path.Combine(projectDirectory, DataFolder); using (var directoryWriter = new SafeDirectoryWriter(targetDirectory)) { // Write the index { var indexRoot = new TinyObject { { "FormatVersion", Version }, { "MapsetPath", PathHelper.WithStandardSeparators(MapsetPath) }, { "BeatmapId", MainBeatmap.Id }, { "BeatmapName", MainBeatmap.Name }, { "Assemblies", importedAssemblies }, { "Layers", layerManager.Layers.Select(l => l.Guid.ToString("N")) }, }; var indexPath = directoryWriter.GetPath("index.yaml"); indexRoot.Write(indexPath); } // Write user specific data { var userRoot = new TinyObject { { "FormatVersion", Version }, { "Editor", Program.FullName }, { "OwnsOsb", OwnsOsb }, }; var userPath = directoryWriter.GetPath("user.yaml"); userRoot.Write(userPath); } // Write each effect foreach (var effect in effects) { var effectRoot = new TinyObject { { "FormatVersion", Version }, { "Name", effect.Name }, { "Script", effect.BaseName }, }; var configRoot = new TinyObject(); effectRoot.Add("Config", configRoot); foreach (var field in effect.Config.SortedFields) { var fieldRoot = new TinyObject { { "Type", field.Type.FullName }, { "Value", ObjectSerializer.ToString(field.Type, field.Value) }, }; if (field.DisplayName != field.Name) { fieldRoot.Add("DisplayName", field.DisplayName); } configRoot.Add(field.Name, fieldRoot); if ((field.AllowedValues?.Length ?? 0) > 0) { var allowedValuesRoot = new TinyObject(); fieldRoot.Add("AllowedValues", allowedValuesRoot); foreach (var allowedValue in field.AllowedValues) { allowedValuesRoot.Add(allowedValue.Name, ObjectSerializer.ToString(field.Type, allowedValue.Value)); } } } var layersRoot = new TinyObject(); effectRoot.Add("Layers", layersRoot); foreach (var layer in layerManager.Layers.Where(l => l.Effect == effect)) { var layerRoot = new TinyObject { { "Name", layer.Identifier }, { "OsbLayer", layer.OsbLayer }, { "DiffSpecific", layer.DiffSpecific }, { "Visible", layer.Visible }, }; layersRoot.Add(layer.Guid.ToString("N"), layerRoot); } var effectPath = directoryWriter.GetPath("effect." + effect.Guid.ToString("N") + ".yaml"); effectRoot.Write(effectPath); } directoryWriter.Commit(); changed = false; } }