Пример #1
0
        public bool Read()
        {
            if (!File.Exists(Filepath))
            {
                Logger.Write("File not found : " + Filepath, LogType.Error);
                return(false);
            }
            string text = File.ReadAllText(Filepath);

            NovaParsingErrorHandler parsingErrorHandler = new NovaParsingErrorHandler();

            var inputStream = new AntlrInputStream(text);
            var lexer       = new NovaLexer(inputStream);

            lexer.RemoveErrorListener(ConsoleErrorListener <int> .Instance);

            var commonTokenStream = new CommonTokenStream(lexer);
            var parser            = new NovaParser(commonTokenStream);

            parser.RemoveErrorListener(ConsoleErrorListener <IToken> .Instance);
            parser.AddErrorListener(parsingErrorHandler);

            NovaParser.CompilationUnitContext ectx = parser.compilationUnit();

            foreach (var importDeclaration in ectx.importDeclaration())
            {
                Usings.Add(new Using(UsingType.Ref, importDeclaration.fileName().GetText()));
            }
            ClassListener classListener = new ClassListener(this);

            foreach (var typeDeclaration in ectx.typeDeclaration())
            {
                typeDeclaration.EnterRule(classListener);
            }

            //Console.WriteLine(ectx.ToStringTree(parser));

            return(parsingErrorHandler.ErrorsCount == 0);
        }
 /// <summary>
 /// Exit a parse tree produced by <see cref="NovaParser.compilationUnit"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitCompilationUnit([NotNull] NovaParser.CompilationUnitContext context)
 {
 }