Пример #1
0
        private void btnPostProcess_Click(object sender, EventArgs e)
        {
            if (cmbPostProcess.SelectedIndex < 0 || cboGrammar.SelectedIndex < 0)
            {
                return;
            }
            SampleInfo              selectedSample = (SampleInfo)cboGrammar.Items[cboGrammar.SelectedIndex];
            PegNode                 root           = (PegNode)(tvParseTree.Nodes.Count == 0 ? null : tvParseTree.Nodes[0].Tag);
            TextBoxWriter           errOut         = new TextBoxWriter(Output);
            ParserPostProcessParams postProcParams;

            if (selectedSample.startRule.Target is PegCharParser)
            {
                string grammarFileName, src;
                GetGrammarFileNameAndSource((PegCharParser)selectedSample.startRule.Target, root.id_, out grammarFileName, out src);
                postProcParams = new ParserPostProcessParams(GetOutputDirectory(), GetSourceFileTitle(), grammarFileName, root, src, errOut);
            }
            else
            {
                string grammarFileName;
                byte[] src;
                GetGrammarFileNameAndSource((PegByteParser)selectedSample.startRule.Target, root.id_, out grammarFileName, out src);
                postProcParams = new ParserPostProcessParams(GetOutputDirectory(), GetSourceFileTitle(), grammarFileName, root, src, errOut);
            }
            var selectedPostProcessor = (IParserPostProcessor)cmbPostProcess.Items[cmbPostProcess.SelectedIndex];

            if (selectedPostProcessor != null)
            {
                selectedPostProcessor.Postprocess(postProcParams);
            }
        }
Пример #2
0
        public void CreateHtml()
        {
            pegSrc = File.ReadAllText(_htmlPEGFile);
            root   = PegRunUtils.ParsePegGrammar(pegSrc, errOut);
            var postProcParams = new ParserPostProcessParams(GetOutputDirectory(), "Html", "Html", root, pegSrc, errOut);

            PegRunUtils.CreatePegCodeFile(postProcParams);
        }
Пример #3
0
 internal TreeContext(ParserPostProcessParams generatorParams)
 {
     generatorParams_ = generatorParams;
     root_            = generatorParams.root_;
     byteSrc_         = generatorParams.byteSrc_;
     errOut_          = generatorParams.errOut_;
     sErrorPrefix     = "<BER_DEFINITE_CONVERTER> FILE:'" + generatorParams_.grammarFileName_ + "' ";
 }
        public void Postprocess(ParserPostProcessParams postProcessorParams)
        {
            _root            = postProcessorParams.root_;
            _src             = postProcessorParams.src_;
            _generatorParams = postProcessorParams;

            OpenOutFile("", ".html");
            GenHtmlForBlock();
        }
Пример #5
0
        public void CreateHtml()
        {
            pegSrc = File.ReadAllText(_htmlPEGFile);
            if (RunImpl(pegSrc, errOut))
            {
                var postProcParams = new ParserPostProcessParams(GetOutputDirectory(), "Html", "Html", root, pegSrc, errOut);

                var postProcessor = (IParserPostProcessor) new PegParserGenerator();
                if (postProcessor != null)
                {
                    postProcessor.Postprocess(postProcParams);
                }
            }
        }
Пример #6
0
        public void CreateHtml(string markdownSrc)
        {
            if (CreatePeg(markdownSrc))
            {
                var postProcParams = new ParserPostProcessParams(
                    _outputFolder
                    , _outputFileName, "Markdown", root, markdownSrc, errOut);

                var postProcessor = (IParserPostProcessor) new MarkdownHtmlGenerator();
                if (postProcessor != null)
                {
                    postProcessor.Postprocess(postProcParams);
                }
            }
        }
Пример #7
0
        void IParserPostProcessor.Postprocess(ParserPostProcessParams postProcessorParams)
        {
            context_ = new TreeContext(postProcessorParams);
            string outDir = PUtils.MakeFileName("", context_.generatorParams_.outputDirectory_, "DefiniteLengthForm");

            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }
            string outFile = PUtils.MakeFileName(context_.generatorParams_.sourceFileTitle_, outDir);

            using (BinaryWriter rw = new BinaryWriter(File.Open(outFile, FileMode.Create)))
            {
                WriteDefinite(rw, context_.generatorParams_.root_);
                context_.generatorParams_.errOut_.WriteLine("INFO  from <BER_DEFINITE_ENCODER> {0} bytes written to '{1}'",
                                                            rw.BaseStream.Position, outFile);
            }
        }
Пример #8
0
 void IParserPostProcessor.Postprocess(ParserPostProcessParams postProcessorParams)
 {
     Session.Eval(postProcessorParams.root_, postProcessorParams.src_, postProcessorParams.errOut_);
 }