Exemplo n.º 1
0
 bool RunImpl(ESampleId eSampleId, byte[] src, TextWriter Fout, out PegNode tree)
 {
     SampleInfo sample = sampleGrammars.Find(si => si.grammarId == eSampleId);
     if (sample.startRule.Target is PegByteParser)
     {
         try
         {
             PegByteParser pg = (PegByteParser)sample.startRule.Target;
             pg.Construct(src, Fout);
             bool bMatches = sample.startRule();
             tree = ((PegByteParser)sample.startRule.Target).GetRoot();
             return bMatches;
         }
         catch (PegException)
         {
             tree = ((PegByteParser)sample.startRule.Target).GetRoot();
             return false;
         }
     }
     Debug.Assert(false); tree = null; return false;
 }
Exemplo n.º 2
0
        bool RunImpl(ESampleId eSampleId, string src, TextWriter Fout, out PegNode tree)
        {
            SampleInfo sample = sampleGrammars.Find(si => si.grammarId == eSampleId);

            if (sample.startRule.Target is PegCharParser)
            {
                try
                {
                    PegCharParser pg = (PegCharParser)sample.startRule.Target;
                    pg.Construct(src, Fout);
                    pg.SetSource(src);
                    pg.SetErrorDestination(Fout);
                    bool bMatches = sample.startRule();
                    tree = ((PegCharParser)sample.startRule.Target).GetRoot();
                    return(bMatches);
                }
                catch (PegException)
                {
                    tree = ((PegCharParser)sample.startRule.Target).GetRoot();
                    return(false);
                }
            }
            Debug.Assert(false); tree = null; return(false);
        }
Exemplo n.º 3
0
        void LoadSourceFile(string path)
        {
            txtSource.Tag = null;
            txtSource.ReadOnly = false;
            tvParseTree.Nodes.Clear();
            HidePostProcessButtons();
            cmbPostProcess.DataSource = null;

            SampleInfo selectedSample;
            if (path.Length == 0)
            {
                selectedSample = new SampleInfo();
                txtSource.Tag = new SourcefileInfo(path, EncodingClass.ascii, "");
            }else
            {
                if (cboGrammar.SelectedIndex < 0)
                {
                    MessageBox.Show("Grammar must be selected first");
                    return;
                }
                this.Text = "Parsing Expression Grammar Explorer (" + path.Substring(path.LastIndexOf('\\') + 1) + ")";
                selectedSample = (SampleInfo)cboGrammar.Items[cboGrammar.SelectedIndex];
                try
                {
                    FileLoader loader = new FileLoader(selectedSample.GetEncodingClass(), selectedSample.GetUnicodeDetection(), path);
                    if (loader.IsBinaryFile())
                    {
                        byte[] bytes;
                        loader.LoadFile(out bytes);
                        txtSource.Tag = new SourcefileInfo(path, selectedSample.GetEncodingClass(), bytes);
                        string src = BuildHexView(bytes);
                        DisplaySrc(src, path, src.Length);
                        txtSource.ReadOnly = true;
                    }
                    else
                    {
                        string src;
                        loader.LoadFile(out src);
                        txtSource.Tag = new SourcefileInfo(path, selectedSample.GetEncodingClass(), src);
                        DisplaySrc(src, path, src.Length);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
        }