Пример #1
0
        public static SettingSyntaxTree ParseSettings(string json, SettingSchema schema)
        {
            RootJsonSyntax rootNode = JsonParser.Parse(json);
            var            errors   = rootNode.Errors;

            // It is important to use green nodes here, so the schema doesn't need to create the entire parse tree to type-check its values.
            // Instead, schema.TryCreateValue accepts a rootNodeStart parameter to generate errors at the right locations.
            if (rootNode.Syntax.Green.ValueNode.ContentNode is GreenJsonMissingValueSyntax)
            {
                return(new SettingSyntaxTree(rootNode, null));
            }

            int rootNodeStart = rootNode.Syntax.Green.ValueNode.BackgroundBefore.Length;

            if (schema.TryCreateValue(
                    json,
                    rootNode.Syntax.Green.ValueNode.ContentNode,
                    out SettingObject settingObject,
                    rootNodeStart,
                    errors).IsOption1(out ITypeErrorBuilder typeError))
            {
                errors.Add(ValueTypeError.Create(typeError, rootNode.Syntax.Green.ValueNode.ContentNode, json, rootNodeStart));
                return(new SettingSyntaxTree(rootNode, null));
            }

            return(new SettingSyntaxTree(rootNode, settingObject));
        }
Пример #2
0
        public SettingWriter(SettingSchema schema, SettingWriterOptions options)
        {
            this.schema  = schema;
            this.options = options;

            // Write schema description, if any.
            AppendCommentLines(schema.Description);
        }
Пример #3
0
        public static string ConvertToJson(PMap map, SettingSchema schema, SettingWriterOptions options)
        {
            SettingWriter writer = new SettingWriter(schema, options);

            writer.Visit(map);

            // End files with a newline character.
            writer.outputBuilder.AppendLine();
            return(writer.outputBuilder.ToString());
        }
Пример #4
0
 internal SettingObject(SettingSchema schema, PMap map)
 {
     Schema = schema;
     Map    = map;
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of <see cref="SettingCopy"/>.
 /// </summary>
 /// <param name="schema">
 /// The schema to use.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="schema"/> is null.
 /// </exception>
 public SettingCopy(SettingSchema schema)
 {
     Schema          = schema ?? throw new ArgumentNullException(nameof(schema));
     KeyValueMapping = new Dictionary <string, PValue>();
 }