internal TreeContext(ParserPostProcessParams generatorParams) { generatorParams_ = generatorParams; root_ = generatorParams.root_; byteSrc_ = generatorParams.byteSrc_; errOut_ = generatorParams.errOut_; sErrorPrefix = "<BER_DEFINITE_CONVERTER> FILE:'" + generatorParams_.grammarFileName_ + "' "; }
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); } }
static void Main(string[] args) { if(args.Count()==0) throw new ArgumentException("arguments requires", "args"); var input = args[0]; var output = args[1]; var src = File.ReadAllText(input); PegCharParser.Matcher startRule = (new PegGrammarParser()).peg_module; var pg = (PegCharParser)startRule.Target; pg.Construct(src, Console.Out); pg.SetSource(src); pg.SetErrorDestination(Console.Out); bool bMatches = startRule(); var tree = ((PegCharParser)startRule.Target).GetRoot(); IParserPostProcessor generator = new PegParserGenerator(); var postProcParams = new ParserPostProcessParams(output, "", "", tree, src, Console.Out); generator.Postprocess(postProcParams); Console.ReadLine(); }
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); } }
void IParserPostProcessor.Postprocess(ParserPostProcessParams postProcessorParams) { Session.Eval(postProcessorParams.root_, postProcessorParams.src_, postProcessorParams.errOut_); }
void IParserPostProcessor.Postprocess(ParserPostProcessParams postProcessorParams) { TreeContext context = new TreeContext(postProcessorParams); var checker = new CheckGrammar(context); if (!checker.bOk_) return; var normalize = new NormalizeTree(context,checker.setRules_); if (!normalize.bOk_) return; Peg.CSharp.PegCSharpGenerator cSharpGenerator = new Peg.CSharp.PegCSharpGenerator(context); }
public TreeContext(ParserPostProcessParams generatorParams) { generatorParams_ = generatorParams; root_ = generatorParams.root_; src_ = generatorParams.src_; errOut_ = generatorParams.errOut_; dictProperties_ = new Dictionary<string, string>(); dictNameRuleObj_ = new Dictionary<string, PegNode>(); semanticInfoNodes_ = new HashSet<PegNode>(); dictSemanticInfo_ = new Dictionary<string, PegNode>();//member_name -> named/anonym-semanticblock referencedMembers_ = new HashSet<string>(); sErrorPrefix = "<PEG_PARSER> FILE:'" + generatorParams_.grammarFileName_ + "' "; RegisterRules(); RegisterProperties(); RegisterSemanticMembers(); }