コード例 #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 void ParseTreeTests(string json, ExpectedJsonTree parseTree, JsonErrorCode[] expectedErrors)
        {
            RootJsonSyntax rootSyntax = JsonParser.Parse(json);

            AssertParseTree(parseTree, null, 0, rootSyntax.Syntax);

            // Assert expected errors.
            Assert.Collection(
                rootSyntax.Errors,
                Enumerable.Range(0, expectedErrors.Length)
                .Select <int, Action <JsonErrorInfo> >(i => errorInfo => Assert.Equal(expectedErrors[i], errorInfo.ErrorCode))
                .ToArray());
        }
コード例 #3
0
 private SettingSyntaxTree(RootJsonSyntax jsonSyntaxTree, SettingObject settingObject)
 {
     JsonSyntaxTree = jsonSyntaxTree;
     SettingObject  = settingObject;
 }