Beispiel #1
0
        private void ParseUsingDefs(ParseTreeNode node, Context context)
        {
            _currentNode = node;

            foreach (var child in node.ChildNodes)
            {
                switch (child.Term.Name)
                {
                    case SchematraGrammer.term_using_def:
                        ParseUsingDef(child, context);
                        break;
                }
            }
        }
Beispiel #2
0
        public TypeContext Build(String[] filePaths)
        {
            if (filePaths.Length <= 0)
                throw new SchematraException("Files were not specified");

            var typeContext = new TypeContext();
            var context = new Context(typeContext);

            foreach (var filePath in filePaths)
            {
                var tree = BuildParseTree(filePath);

                try
                {
                    ParseUnit(tree, context);
                    return typeContext;
                }
                catch (Exception ex)
                {
                    var errorMessage = "Unaxpected exception while parsing schema file";

                    if (_currentNode != null)
                        errorMessage = BuildErrorMessage(ex.Message, filePath, _currentNode.Span.Location.Line + 1, _currentNode.Span.Location.Column);

                    throw new SchematraException(errorMessage);
                }
            }

            throw new SchematraException("Files were not specified");
        }
Beispiel #3
0
 private void ParseUnit(ParseTree tree, Context context)
 {
     foreach (var child in tree.Root.ChildNodes)
     {
         switch (child.Term.Name)
         {
             case SchematraGrammer.term_defs:
                 ParseDefs(child, context, "");
                 break;
             case SchematraGrammer.term_using_defs:
                 ParseUsingDefs(child, context);
                 break;
         }
     }
 }
Beispiel #4
0
        private void ParseUsingDef(ParseTreeNode node, Context context)
        {
            _currentNode = node;

            foreach (var child in node.ChildNodes)
            {
                switch (child.Term.Name)
                {
                    case SchematraGrammer.term_using_def_name:
                        context.AddUsing(child.Token.ValueString);
                        break;
                }
            }
        }
Beispiel #5
0
        private void ParseSchemaDefOption(ParseTreeNode node, Context context, RecordTypeBuilder recordBuilder)
        {
            _currentNode = node;

            foreach (var child in node.ChildNodes)
            {
                switch (child.Term.Name)
                {
                    case SchematraGrammer.term_schema_def_tagged_option:
                        ParseSchemaDefTaggedOption(child, recordBuilder);
                        break;
                    case SchematraGrammer.term_schema_def_extends_option:
                        ParseSchemaDefExtendsOption(child, context, recordBuilder);
                        break;
                }
            }
        }
Beispiel #6
0
        private void ParseSchemaDefOptions(ParseTreeNode node, Context context, RecordTypeBuilder recordBuilder)
        {
            _currentNode = node;

            if (node.ChildNodes.Count <= 0)
                return;

            foreach (var child in node.ChildNodes)
            {
                switch (child.Term.Name)
                {
                    case SchematraGrammer.term_schema_def_option:
                        ParseSchemaDefOption(child, context, recordBuilder);
                        break;
                }
            }
        }
Beispiel #7
0
        private void ParseSchemaDefBody(ParseTreeNode node, Context context, RecordTypeBuilder recordBuilder)
        {
            _currentNode = node;

            foreach (var child in node.ChildNodes)
            {
                switch (child.Term.Name)
                {
                    case SchematraGrammer.term_field:
                        ParseField(child, context, recordBuilder);
                        break;
                }
            }
        }
Beispiel #8
0
        private void ParseSchemaDefExtendsOption(ParseTreeNode node, Context context, RecordTypeBuilder recordBuilder)
        {
            _currentNode = node;

            foreach (var child in node.ChildNodes)
            {
                switch (child.Term.Name)
                {
                    case SchematraGrammer.term_schema_def_extends:
                        recordBuilder.SetBaseType(new TypeResolver(child.Token.ValueString, context.Usings));
                        break;
                }
            }
        }
Beispiel #9
0
        private void ParseSchemaDef(ParseTreeNode node, Context context, string space)
        {
            _currentNode = node;

            var recordBuilder = new RecordTypeBuilder(context.TypeContext);

            foreach (var child in node.ChildNodes)
            {
                switch (child.Term.Name)
                {
                    case SchematraGrammer.term_schema_def_name:
                        recordBuilder.SetName(child.Token.Text, space);
                        break;

                    case SchematraGrammer.term_schema_def_options:
                        ParseSchemaDefOptions(child, context, recordBuilder);
                        break;

                    case SchematraGrammer.term_schema_def_body:
                        ParseSchemaDefBody(child, context, recordBuilder);
                        break;
                }
            }

            context.TypeContext.AddType(recordBuilder.Create());
        }
Beispiel #10
0
        private void ParseNamespaceDef(ParseTreeNode node, Context context, string space)
        {
            _currentNode = node;

            var namespaceText = String.Empty;

            foreach (var child in node.ChildNodes)
            {
                switch (child.Term.Name)
                {
                    case SchematraGrammer.term_namespace_def_name:
                        namespaceText = child.Token.ValueString;
                        break;
                    case SchematraGrammer.term_defs:
                        ParseDefs(child, context, Utils.ConcatNamespaces(space, namespaceText));
                        break;
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Parsing of field nonterm
        /// </summary>
        private void ParseField(ParseTreeNode node, Context context, RecordTypeBuilder recordBuilder)
        {
            _currentNode = node;

            Int32 index = 0;
            FieldQualifier qualifier = FieldQualifier.Optional;
            String typeName = "";
            String name = "";
            Object defaultValue = null;

            foreach (var child in node.ChildNodes)
            {
                if (child.Term == null || child.Term.Name == null)
                    continue;

                switch (child.Term.Name)
                {
                    case SchematraGrammer.term_field_index:
                        index = Int32.Parse(child.Token.Value.ToString());
                        break;

                    case SchematraGrammer.term_field_qualifier:
                        qualifier = GetQualifierByString(child.ChildNodes[0].Term.Name);
                        break;

                    case SchematraGrammer.term_field_nullable:
                        //                        fieldDefinition.Nullable = child.ChildNodes.Count > 0;
                        break;

                    case SchematraGrammer.term_field_schema:
                        typeName = child.Token.Value.ToString();
                        break;

                    case SchematraGrammer.term_field_name:
                        name = child.Token.Value.ToString();
                        break;

                    case SchematraGrammer.term_field_init_value:

                        // yes, too cryptic
                        if (child.ChildNodes.Count > 0 && child.ChildNodes[0].ChildNodes.Count > 0)
                            defaultValue = child.ChildNodes[0].ChildNodes[0].Token.Value;

                        break;
                }
            }

            recordBuilder.AddField(index, name, new TypeResolver(typeName, context.Usings), qualifier, defaultValue);
        }
Beispiel #12
0
        private void ParseDefs(ParseTreeNode node, Context context, string space)
        {
            _currentNode = node;

            if (node.Term.Name != SchematraGrammer.term_defs)
                return;

            foreach (var child in node.ChildNodes)
            {
                switch (child.Term.Name)
                {
                    case SchematraGrammer.term_def:
                        ParseDef(child, context, space);
                        break;
                }
            }
        }
Beispiel #13
0
        private void ParseDef(ParseTreeNode node, Context context, string space)
        {
            _currentNode = node;

            foreach (var child in node.ChildNodes)
            {
                switch (child.Term.Name)
                {
                    case SchematraGrammer.term_schema_def:
                        ParseSchemaDef(child, context, space);
                        break;
                    case SchematraGrammer.term_namespace_def:
                        ParseNamespaceDef(child, context, space);
                        break;
                }
            }
        }