Exemple #1
0
        public void TestEvalution()
        {
            string              docPath             = @"E:\桌面工作目录\正在进行的\My Little Pony Novel\无限维度\main.pony";
            ErrorListener       listener            = new ErrorListener();
            GlobalConfiguration globalConfiguration = GlobalConfiguration.Instance;
            PonyLexer           lexer  = new PonyLexer();
            PonyParser          parser = new PonyParser(lexer);

            lexer.errorListener  = globalConfiguration.ParserErrorListener;
            parser.errorListener = globalConfiguration.ParserErrorListener;
            PonyTextStructureBase structureBase = parser.Parse(File.ReadAllText(docPath));

            AssemblyInjectionManager injectionManager = new AssemblyInjectionManager();

            injectionManager.RegisterAssembly("PonyTextRenderer.Pdf", Assembly.GetAssembly(typeof(PdfRenderer)));
            injectionManager.RegisterAssembly("PonyText.Processor", Assembly.GetAssembly(typeof(PonyParser)));

            IProcessorFactory processor         = new ProcessorFactory(new ProcessorExperience(), injectionManager);
            SimpleTextContext simpleTextContext = new SimpleTextContext(processor, new TextElementFactory());

            processor.LoadProcessorFrom("PonyText.Processor");

            structureBase.Evaluate(simpleTextContext);

            PdfRenderer pdfRenderer = new PdfRenderer(simpleTextContext);

            simpleTextContext.GetCurrentContext().Render(pdfRenderer, simpleTextContext);

            using (FileStream fs = new FileStream("out.pdf", FileMode.Create)) {
                pdfRenderer.RenderContentTo(fs);
            }
        }
Exemple #2
0
        public void Test6()
        {
            string    docPath = @"E:\桌面工作目录\正在进行的\Projects\PonyText\README_PonyText.pony";
            PonyLexer lexer   = new PonyLexer();

            lexer.onTokenGenerated += Lexer_onTokenGenerated;
            lexer.errorListener     = new ErrorListener();
            bool res = lexer.RunGenerator(File.ReadAllText(docPath));

            Assert.IsTrue(res);
        }
Exemple #3
0
        public void Test5()
        {
            string    docPath = @"E:\桌面工作目录\正在进行的\My Little Pony Novel\无限维度\main.pony";
            PonyLexer lexer   = new PonyLexer();

            lexer.onTokenGenerated += Lexer_onTokenGenerated;
            lexer.errorListener     = new ErrorListener();
            bool res = lexer.RunGenerator(File.ReadAllText(docPath));

            Assert.IsTrue(res);
        }
Exemple #4
0
        public void Test3()
        {
            string    docPath = "test/case3.txt";
            PonyLexer lexer   = new PonyLexer();

            lexer.onTokenGenerated += Lexer_onTokenGenerated;
            lexer.errorListener     = new ErrorListener();
            bool res = lexer.RunGenerator(File.ReadAllText(docPath));

            Assert.IsFalse(res);
        }
Exemple #5
0
        public static PonyTextStructureBase CreateEvaluable(string ponyTextContent, string ponyTextIdentifier, PonyTextContext ctx)
        {
            ctx.Metadata.DependencyList.AddDependency(ponyTextIdentifier);

            PonyLexer  ponyLexer = new PonyLexer();
            PonyParser parser    = new PonyParser(ponyLexer);

            parser.errorListener    = GlobalConfiguration.Instance.ParserErrorListener;
            ponyLexer.errorListener = parser.errorListener;

            return(parser.Parse(ponyTextContent));
        }
Exemple #6
0
        public void TestParser2()
        {
            string        docPath  = @"E:\桌面工作目录\正在进行的\Projects\PonyText\README_PonyText.pony";
            ErrorListener listener = new ErrorListener();
            PonyLexer     lexer    = new PonyLexer();
            PonyParser    parser   = new PonyParser(lexer);

            lexer.errorListener  = listener;
            parser.errorListener = listener;
            PonyTextStructureBase structureBase = parser.Parse(File.ReadAllText(docPath));

            Assert.IsNotNull(structureBase);
        }
Exemple #7
0
        public void TestParser1()
        {
            string        docPath  = @"E:\桌面工作目录\正在进行的\My Little Pony Novel\无限维度\chapters\chap1.pony";
            ErrorListener listener = new ErrorListener();
            PonyLexer     lexer    = new PonyLexer();
            PonyParser    parser   = new PonyParser(lexer);

            lexer.errorListener  = listener;
            parser.errorListener = listener;
            PonyTextStructureBase structureBase = parser.Parse(File.ReadAllText(docPath));

            Assert.IsNotNull(structureBase);
        }
Exemple #8
0
        public void TestEvalution2()
        {
            string        docPath  = @"E:\桌面工作目录\正在进行的\Projects\PonyText\README_PonyText.pony";
            ErrorListener listener = new ErrorListener();
            PonyLexer     lexer    = new PonyLexer();
            PonyParser    parser   = new PonyParser(lexer);

            lexer.errorListener  = listener;
            parser.errorListener = listener;

            PonyTextStructureBase    structureBase    = parser.Parse(File.ReadAllText(docPath));
            AssemblyInjectionManager injectionManager = new AssemblyInjectionManager();

            injectionManager.RegisterAssembly("PonyTextRenderer.Markdown", Assembly.GetAssembly(typeof(MarkdownRenderer)));
            injectionManager.RegisterAssembly("PonyText.Processor", Assembly.GetAssembly(typeof(PonyParser)));

            IProcessorFactory processor         = new ProcessorFactory(new ProcessorExperience(), injectionManager);
            SimpleTextContext simpleTextContext = new SimpleTextContext(processor, new TextElementFactory());

            processor.LoadProcessorFrom("PonyText.Processor");

            Assert.DoesNotThrow(() => {
                structureBase.Evaluate(simpleTextContext);
            });

            using (FileStream fs = new FileStream("dump.json", FileMode.Create)) {
                using (StreamWriter sw = new StreamWriter(fs)) {
                    sw.Write(simpleTextContext.GetCurrentContext().ToString());
                }
            }

            MarkdownRenderer stringRenderer = new MarkdownRenderer();

            simpleTextContext.GetCurrentContext().Render(stringRenderer, simpleTextContext);

            using (FileStream fs = new FileStream("out.md", FileMode.Create)) {
                stringRenderer.RenderContentTo(fs);
            }
        }