Exemplo n.º 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;
        }
Exemplo n.º 2
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;
        }