示例#1
0
        private void RoundtripCheck(string src)
        {
            sphereScript99Parser.FileContext file = null;
            Parse(src, parser =>
            {
                file = parser.file();
            });

            var roundtripGenerator = new RoundtripGenerator();

            roundtripGenerator.Visit(file);

            var srcWithoutEofTail = src.Substring(0, src.IndexOf("[eof]") + 5);

            roundtripGenerator.Output.Should().Be(srcWithoutEofTail);
        }
示例#2
0
        private void RoundtripFile(string inputFileName, string outputFileName)
        {
            if (inputFileName.Equals(outputFileName, StringComparison.OrdinalIgnoreCase))
            {
                throw new CommandLineException("Cannot parse and write to the same file.");
            }

            var inputStream = new AntlrInputStream(File.OpenRead(inputFileName));
            var lexer       = new sphereScript99Lexer(inputStream);
            var tokenStream = new CommonTokenStream(lexer);
            var parser      = new sphereScript99Parser(tokenStream);

            parser.AddErrorListener(new ConsoleErrorListener());

            System.Console.WriteLine($"Parsing {inputFileName}");
            var file = parser.file();

            System.Console.WriteLine($"Writing {outputFileName}");
            var generator = new RoundtripGenerator();

            generator.Visit(file);

            File.WriteAllText(outputFileName, generator.Output);
        }