예제 #1
0
        //static public string TIKZEDT_CMD_COMMENT = "";

        public static Tikz_ParseTree ParseInputFile(string code)
        {
            //if code is empty to bother ANTLR (it will raise an exception)
            if (code.Trim() == "")
            {
                return(null);
            }

            simpletikzLexer   lex    = new simpletikzLexer(new ANTLRStringStream(code));
            CommonTokenStream tokens = new CommonTokenStream(lex);
            simpletikzParser  parser = new simpletikzParser(tokens);

            simpletikzParser.tikzdocument_wo_tikzpicture_return ret = parser.tikzdocument_wo_tikzpicture();
            CommonTree     t       = (CommonTree)ret.Tree;
            Tikz_ParseTree root    = new Tikz_ParseTree();
            bool           success = FillItem(root, t, tokens);

            if (success)
            {
                root.RegisterNodeAndStyleRefs(); // make a list with all node names for later reference
                return(root);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        private void Parse()
        {
            simpletikzLexer lex = new simpletikzLexer(new ANTLRStringStream(Code));
            CommonTokenStream tokens = new CommonTokenStream(lex);
            simpletikzParser parser = new simpletikzParser(tokens);

            
            

        }
예제 #3
0
        //static public string TIKZEDT_CMD_COMMENT = "";

        public static Tikz_ParseTree ParseInputFile(string code)
        {
            //if code is empty to bother ANTLR (it will raise an exception)
            if (code.Trim() == "")
                return null;            

            simpletikzLexer lex = new simpletikzLexer(new ANTLRStringStream(code));
            CommonTokenStream tokens = new CommonTokenStream(lex);
            simpletikzParser parser = new simpletikzParser(tokens);
            simpletikzParser.tikzdocument_wo_tikzpicture_return ret = parser.tikzdocument_wo_tikzpicture();
            CommonTree t = (CommonTree)ret.Tree;
            Tikz_ParseTree root = new Tikz_ParseTree();
            bool success = FillItem(root, t, tokens);
            if (success)
            {
                root.RegisterNodeAndStyleRefs(); // make a list with all node names for later reference                
                return root;
            }
            else
                return null;
        }
예제 #4
0
 private void Parse()
 {
     simpletikzLexer   lex    = new simpletikzLexer(new ANTLRStringStream(Code));
     CommonTokenStream tokens = new CommonTokenStream(lex);
     simpletikzParser  parser = new simpletikzParser(tokens);
 }
예제 #5
0
        public static Tikz_ParseTree Parse(string code)
        {
            code = PrepareCodeForParsing(code);

            //if code is empty to bother ANTLR (it will raise an exception)
            if (code.Trim() == "")
                return null;

            simpletikzLexer lex = new simpletikzLexer(new ANTLRStringStream(code));
            CommonTokenStream tokens = new CommonTokenStream(lex);

            //for (int i = 0; i < tokens.Count; i++)
            //{
            //    string ds = tokens.Get(i).Text;
            //    ds = ds + "eee";
            //}

            simpletikzParser parser = new simpletikzParser(tokens);

            //tikzgrammarParser.expr_return r =            
            simpletikzParser.tikzdocument_return ret = parser.tikzdocument();
            
            //CommonTreeAdaptor adaptor = new CommonTreeAdaptor();
            CommonTree t = (CommonTree)ret.Tree;
            //MessageBox.Show(printTree(t,0));



        

/*
        public string printTree(CommonTree t, int indent)
        {
            string s="";
            if ( t != null ) {
		        for ( int i = 0; i < indent; i++ )
			        s = s+"   ";

                string r = "";// s + t.ToString() + "\r\n";
                
                if (t.ChildCount >0)
		            foreach ( object o in t.Children ) {
			            r=r+s+o.ToString()+"\r\n" + printTree((CommonTree)o, indent+1);
                    }

                return r;
            }  else return "";
		}
    }*/
            
            
            Tikz_ParseTree root = new Tikz_ParseTree();

            bool success = FillItem(root, t, tokens);


            // mockup 
            //t.Children.Add(new Tikz_Node(0, 0));
            //t.Children.Add(new Tikz_Node(5, 5));
            //t.Children.Add(new Tikz_Node(6, 8));
            //t.Children.Add(new Tikz_Node(8, 8));
            if (success)
            {
                root.RegisterNodeAndStyleRefs(); // make a list with all node names for later reference
                return root;
            }
            else
                return null;
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string s = Clipboard.GetText();
            simpletikzLexer lex = new simpletikzLexer(new ANTLRStringStream(s));
            CommonTokenStream tokens = new CommonTokenStream(lex);

            for (int i = 0; i < tokens.Count; i++)
            {
                string ds = tokens.Get(i).Text;
                ds = ds + "eee";
            }

            simpletikzParser parser = new simpletikzParser(tokens);

            //tikzgrammarParser.expr_return r =
            simpletikzParser.tikzpath_return ret = parser.tikzpath();
            
            //CommonTreeAdaptor adaptor = new CommonTreeAdaptor();
            CommonTree t = (CommonTree)ret.Tree;
            MessageBox.Show(printTree(t,0));

        }
예제 #7
0
        public static Tikz_ParseTree Parse(string code)
        {
            code = PrepareCodeForParsing(code);

            //if code is empty to bother ANTLR (it will raise an exception)
            if (code.Trim() == "")
            {
                return(null);
            }

            simpletikzLexer   lex    = new simpletikzLexer(new ANTLRStringStream(code));
            CommonTokenStream tokens = new CommonTokenStream(lex);

            //for (int i = 0; i < tokens.Count; i++)
            //{
            //    string ds = tokens.Get(i).Text;
            //    ds = ds + "eee";
            //}

            simpletikzParser parser = new simpletikzParser(tokens);

            //tikzgrammarParser.expr_return r =
            simpletikzParser.tikzdocument_return ret = parser.tikzdocument();

            //CommonTreeAdaptor adaptor = new CommonTreeAdaptor();
            CommonTree t = (CommonTree)ret.Tree;
            //MessageBox.Show(printTree(t,0));



/*
 *      public string printTree(CommonTree t, int indent)
 *      {
 *          string s="";
 *          if ( t != null ) {
 *                      for ( int i = 0; i < indent; i++ )
 *                              s = s+"   ";
 *
 *              string r = "";// s + t.ToString() + "\r\n";
 *
 *              if (t.ChildCount >0)
 *                          foreach ( object o in t.Children ) {
 *                                  r=r+s+o.ToString()+"\r\n" + printTree((CommonTree)o, indent+1);
 *                  }
 *
 *              return r;
 *          }  else return "";
 *              }
 *  }*/


            Tikz_ParseTree root = new Tikz_ParseTree();

            bool success = FillItem(root, t, tokens);


            // mockup
            //t.Children.Add(new Tikz_Node(0, 0));
            //t.Children.Add(new Tikz_Node(5, 5));
            //t.Children.Add(new Tikz_Node(6, 8));
            //t.Children.Add(new Tikz_Node(8, 8));
            if (success)
            {
                root.RegisterNodeAndStyleRefs(); // make a list with all node names for later reference
                return(root);
            }
            else
            {
                return(null);
            }
        }