public static void ParseProgramOrClass(TextSourceInfo textSourceInfo, ISearchableReadOnlyList<CodeElementsLine> codeElementsLines, TypeCobolOptions compilerOptions, SymbolTable customSymbols, out Program newProgram, out Class newClass, out IList<ParserDiagnostic> diagnostics)
        {
            // Create an Antlr compatible token source on top a the token iterator
            CodeElementsLinesTokenSource tokenSource = new CodeElementsLinesTokenSource(
                textSourceInfo.Name,
                codeElementsLines);

            // Init parser
            ITokenStream tokenStream = new TokensLinesTokenStream(tokenSource, Token.CHANNEL_SourceTokens);
            ProgramClassParser cobolParser = new ProgramClassParser(tokenStream);
            // -> activate full ambiguities detection
            //parser.Interpreter.PredictionMode = PredictionMode.LlExactAmbigDetection;

            // Register all parse errors in a list in memory
            DiagnosticSyntaxErrorListener errorListener = new DiagnosticSyntaxErrorListener();
            cobolParser.RemoveErrorListeners();
            cobolParser.AddErrorListener(errorListener);

            // Try to parse a Cobol program or class
            ProgramClassParser.CobolCompilationUnitContext codeElementParseTree = cobolParser.cobolCompilationUnit();

            // Visit the parse tree to build a first class object representing a Cobol program or class
            ParseTreeWalker walker = new ParseTreeWalker();
            CobolNodeBuilder programClassBuilder = new CobolNodeBuilder();
            programClassBuilder.CustomSymbols = customSymbols;
            programClassBuilder.Dispatcher = new NodeDispatcher();
            programClassBuilder.Dispatcher.CreateListeners();
            walker.Walk(programClassBuilder, codeElementParseTree);

            // Register compiler results
            newProgram = programClassBuilder.Program;
            newClass = programClassBuilder.Class;
            diagnostics = errorListener.Diagnostics;
        }
 public ProgramClassDocument(CodeElementsDocument previousStepSnapshot, int programClassVersion, Program program, Class classObj, IList<ParserDiagnostic> diagnostics)
 {
     TextSourceInfo = previousStepSnapshot.TextSourceInfo;
     PreviousStepSnapshot = previousStepSnapshot;
     CurrentVersion = programClassVersion;
     Program = program;
     Class = classObj;
     Diagnostics = diagnostics;
 }
示例#3
0
 internal void Compare(Program program, Class cls, IList<Diagnostic> diagnostics, StreamReader expected)
 {
     string result = ParserUtils.DumpResult(program, cls, diagnostics);
     if (debug) Console.WriteLine("\"" + paths.SamplePath+ "\" result:\n" + result);
     ParserUtils.CheckWithResultReader(paths.SamplePath, result, expected);
 }