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 RunProcedure(VerbRenderOpts opts)
        {
            string docPath = Path.GetFullPath(opts.entryFile);

            logger.LogInfo($"Start rendering...");
            AssemblyInjectionManager injectionManager = new AssemblyInjectionManager();

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

            IProcessorFactory processor         = new ProcessorFactory(injectionManager);
            SimpleTextContext simpleTextContext = new SimpleTextContext(processor);

            processor.LoadProcessorFrom("PonyText.Processor");

            PonyTextStructureBase structureBase = PonyTextFactory.CreateEvaluable(docPath, simpleTextContext);

            try{
                structureBase.Evaluate(simpleTextContext);

                PdfRenderer pdfRenderer = new PdfRenderer(simpleTextContext);
                simpleTextContext.GetCurrentContext().Render(pdfRenderer, simpleTextContext);

                using (FileStream fs = new FileStream(opts.outputFile, FileMode.Create)) {
                    pdfRenderer.RenderContentTo(fs);
                }
                logger.LogInfo($"Exported to {opts.outputFile}");
            }
            catch (Exception e) {
                logger.LogError(e.Message);
                if (e is PreProcessorException)
                {
                    PreProcessorException ppe = e as PreProcessorException;
                    foreach (var item in ppe.GetPonyTextStackTrace())
                    {
                        logger.LogError(item);
                    }
                }
                logger.LogError($"Error in file {docPath}");
                logger.LogDebug(e.StackTrace);
            }
        }
Exemple #3
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);
            }
        }