Ejemplo n.º 1
0
        public (ProtoFile File, Scope Scope) LoadFromFile(string filename)
        {
            var             content = File.ReadAllText(filename);
            ICharStream     stream  = CharStreams.fromstring(content);
            ITokenSource    lexer   = new Protobuf3Lexer(stream);
            ITokenStream    tokens  = new CommonTokenStream(lexer);
            Protobuf3Parser parser  = new Protobuf3Parser(tokens);

            parser.AddErrorListener(_errorListener);
            var context = parser.proto();

            _errorListener.EnsureNoErrors();

            var node  = context.file;
            var scope = _scope.CreateScope();

            if (node.Imports.Any())
            {
                LoadImports(node, scope, filename);
            }

            node.CheckSemantic(scope, _reporter);

            _reporter.EnsureNoErrors();
            return(node, scope);
        }