public static SchemaContext BuildSchema(UglNode root) { var context = ApplySchema(root, MetaSchema); var schema = new Schema { Fields = new List <SchemaField>(), Types = new List <SchemaType>() }; if (root.Fields.TryGetValue("fields", out UglNode fieldsNode)) { foreach (var child in fieldsNode.Elements) { schema.Fields.Add(BuildSchemaField(child)); } } if (root.Fields.TryGetValue("types", out UglNode typesNode)) { foreach (var child in fieldsNode.Elements) { schema.Types.Add(BuildSchemaType(child)); } } context.Result = schema; return(context); }
public static SchemaContext ApplySchema(UglNode root, Schema schema, UglOptions options = null) { var typeMap = new Dictionary <string, OneOf <SchemaType, UglType> >(); foreach (var type in UglType.Primitives) { typeMap[type.Key] = type; } var context = new SchemaContext { Root = root, Schema = schema, Types = typeMap, Errors = new List <SchemaError>() }; foreach (var type in options?.Types ?? new List <UglType>()) { context.Types[type.Key] = type; } foreach (var type in schema.Types) { context.Types[type.Key] = type; } var rootType = GetRootType(schema); TypeCheckNode(root, rootType, context); return(context); }
public static UglNode UglParse(IEnumerable <UglLine> lines) { var scopes = new Stack <UglNode>(); var rootScope = new UglNode { Line = new UglLine { LineNumber = -1, Indent = -1, Key = null, Value = null }, Fields = new Dictionary <string, UglNode>(), Elements = new List <UglNode>(), Depth = -1, Type = null }; scopes.Push(rootScope); foreach (var line in lines) { var currentScope = scopes.Peek(); while (line.Indent <= currentScope.Line.Indent) { scopes.Pop(); currentScope = scopes.Peek(); } var node = new UglNode { Line = line, Depth = currentScope.Depth + 1, Fields = new Dictionary <string, UglNode>(), Elements = new List <UglNode>(), Type = null }; if (node.Line.Key == UglNode.ArrayKey) { currentScope.Elements.Add(node); } else { currentScope.Fields[node.Line.Key] = node; } scopes.Push(node); } return(rootScope); }
private static void TypeCheckNode(UglNode root, object rootType, SchemaContext context) { throw new NotImplementedException(); }
private static SchemaType BuildSchemaType(UglNode child) { throw new NotImplementedException(); }