Пример #1
0
        public static CompilationUnit ParseCompilationUnit(ITokenStream TokenParser, SyntaxAssembly Assembly)
        {
            var syntaxParser = new CSyntaxParser(Assembly.Log);
            var unit         = Assembly.CreateCompilationUnit();
            var state        = unit.GetSyntaxState();

            IDeclarationSyntax[] decls;
            try
            {
                decls = syntaxParser.ParseAllDeclarations(TokenParser).ToArray();
            }
            catch (Exception ex)
            {
                Assembly.Log.LogError(new LogEntry(
                                          "error parsing source",
                                          "an error occurred while parsing source code.",
                                          TokenParser.PeekNoTrivia(TokenParser.CurrentPosition).TokenPeek.FullLocation));
                Assembly.Log.LogException(ex);
                throw;
            }


            foreach (var item in decls)
            {
                try
                {
                    item.Declare(state);
                }
                catch (Exception ex)
                {
                    Assembly.Log.LogError(new LogEntry(
                                              "error applying declaration",
                                              "an error occurred while applying a declaration.",
                                              item.GetSourceLocation()));
                    Assembly.Log.LogException(ex);
                    throw;
                }
            }

            return(unit);
        }