Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 private static void TypeCheckNode(UglNode root, object rootType, SchemaContext context)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
 private static SchemaType BuildSchemaType(UglNode child)
 {
     throw new NotImplementedException();
 }