Defines compilation unit that can be compiled
Esempio n. 1
0
        /// <summary>
        /// Compile specified files
        /// </summary>
        public CompilationDefinition BuildCompilationDefinition(String[] filePaths)
        {
            if (filePaths.Length <= 0)
                throw new SchematraException("Files were not specified");

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

                try
                {
                    var compilation = new CompilationDefinition();

                    ParseUnit(tree, compilation);

                    return compilation;
                }
                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");
        }
Esempio n. 2
0
        /// <summary>
        /// Parsing of unit nonterm
        /// </summary>
        private void ParseUnit(ParseTree tree, CompilationDefinition compilation)
        {
            var unitDefinition = new UnitDefinition();

            foreach (var child in tree.Root.ChildNodes)
            {
                switch (child.Term.Name)
                {
                    case SchematraGrammer.term_defs:
                        ParseDefs(child, unitDefinition, "");
                        break;
                    case SchematraGrammer.term_using_defs:
                        ParseUsingDefs(child, unitDefinition);
                        break;
                }
            }

            compilation.Units.Add(unitDefinition);
        }
 /// <summary>
 /// Merge with another compilation definition
 /// </summary>
 public void Merge(CompilationDefinition compilationDefinition)
 {
     units.AddRange(compilationDefinition.Units);
 }
Esempio n. 4
0
 /// <summary>
 /// Initialization
 /// </summary>
 public Parser(CompilationDefinition compilation)
 {
     _compilation = compilation;
     _context = new TypeContext();
 }