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); } }
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)); }
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); }
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); }
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); } }