//此类需要重构，先移出
parser = class{
	ctor(testUnit){
		this.fileStr = ..string.load(testUnit);
		this.spTab = {};
		this.epTab = {};
		this.typeTab = {};
		this.nameTab = {};
		this.argsTab = {};
		this.blockMarkTab = {};
		this.index = 0;
	}
	
	sortAndGetPos = function(spTab){
		var tab2 = {..table.unpack(spTab)};
		var tab3 = {};
		
		..table.sort(spTab);
		
		for(i=1;#tab2){
			for(j=1;#spTab){
				if(spTab[i] == tab2[j]){
					tab3[i] = j;
				}
			}	
		}
		return tab3;
	}
	
	multipleSort = function(tab){
		var mtab ={this.epTab;this.typeTab;this.nameTab;this.argsTab;this.blockMarkTab};
		
		for(i=1;#mtab){
			newTab = {};
			for(j=1;#tab){
				var n = tab[j];
				newTab[j] = mtab[i][n];
			}
			select(i) {
			case 1 
				this.epTab = newTab;
			case 2
				this.typeTab = newTab;
			case 3
				this.nameTab = newTab;
			case 4
				this.argsTab = newTab;
			else
				this.blockMarkTab = newTab;			
			}
		}
	}
	
	getNSBlock = function(str,sp,ep,name){
		var string = ..string.sub(str,sp);
		var s = ..string.match(string,"%{}");
		var startBlockPos = sp-1+#(..string.trimright(..string.sub(str,sp,ep)));
		var endBlockPos = startBlockPos+#s-1;
		var endBlockMark = ..string.format("%c", str[endBlockPos]);
		push(this.spTab,endBlockPos);
		push(this.epTab,endBlockPos);
		push(this.typeTab,"namespace");
		push(this.argsTab,"");
		push(this.nameTab,name);
		push(this.blockMarkTab,endBlockMark);
		this.index ++;
	}
	
	getClassBlock = function(str,sp,ep,name,blockMark){
		var string = ..string.sub(str,sp);
		var  s = "";
		if(blockMark == "{"){
			s = ..string.match(string,"%{}");
		}elseif(blockMark == "begin"){
			s = ..string.match(string,"%<begin><end>");
		}
		var startBlockPos = sp-1+#(..string.trimright(..string.sub(str,sp,ep)));
		var endBlockPos = startBlockPos+#s-1;
		var endBlockMark = ..string.format("%c", str[endBlockPos]);
		push(this.spTab,endBlockPos);
		push(this.epTab,endBlockPos);
		push(this.typeTab,"class");
		push(this.nameTab,name);
		push(this.argsTab,"");
		push(this.blockMarkTab,endBlockMark);
		this.index ++;	
	}
	
	findNS = function(str){
		var strLen = #str;
		var pattern = "<namespace>\s([\w._]+)([\s;{]+)";

		do{
			sp,ep,re1,re2 = ..string.find(str,pattern,ep);
			if(sp && ep && re1 && re2){
				ep -= #re2-#(..string.trimright(re2));
				push(this.spTab,sp);
				push(this.epTab,ep);
				push(this.typeTab,"namespace");
				push(this.nameTab,re1);
				push(this.argsTab,"");
				push(this.blockMarkTab,re2);
				this.index ++;
			}
		}while(ep && ep<strLen)
		
		var tabNum = #(this.nameTab);
		this.index = tabNum;
		
		for(i=1;tabNum){
			if(..string.trim(this.blockMarkTab[i]) == "{"){
				this.getNSBlock(str,this.spTab[i],this.epTab[i],this.nameTab[i]);
			}
		}
	}
	
	findClass = function(str){
		var strLen = #str;
		var startPos = (this.index === 0) ? 1: this.index+1 ;
		var pattern = "[\r\n\t]+([\w_.]*)[\s=]*<class>\s*([{]*)([\w_.]*)\s*([{]*)([begin]*)[\r\n\t]*";

		do{
			sp,ep,re1,re2,re3,re4,re5 = ..string.find(str,pattern,ep);
			if(sp && ep){
				push(this.spTab,sp);
				push(this.epTab,ep);
				push(this.typeTab,"class");
				push(this.argsTab,"");
				if(#re3>0 && #re4>0 || #re5>0){
					push(this.nameTab,re3);
					if(re4){
					 	push(this.blockMarkTab,re4);
					}else{
						push(this.blockMarkTab,re5);
					}		
				}elseif(#re1>0 && #re2>0 || #re3>0){		
					push(this.nameTab,re1);
					if(re2){
						push(this.blockMarkTab,re2);
					}else{
						push(this.blockMarkTab,re3);
					}			
				}
				this.index ++;
			}
		}while(ep && ep< strLen)
		
		var tabNum = #(this.nameTab);

		for(i=startPos;tabNum){
			this.getClassBlock(str,this.spTab[i],this.epTab[i],this.nameTab[i],this.blockMarkTab[i]);
		}
	}
	
	findFunction = function(str){
		var strLen = #str;
		var pattern = "[\r\n\t]+\s*([\w_\.]*)[\s=]*<function>\s*([\w_\.]*)\s*[(]([\w_,;\s=\*\.\34\39]*)[)]\s*([{]*)<begin>*[\r\n\t]*";
	
		do{
			//..io.print(pattern,ep)
			sp,ep,re1,re2,re3,re4 = ..string.find(str,pattern,ep);
			//..io.print(sp,ep,re1,re2,re3,re4);
			if(sp && ep && re1 != "return" && re1 != "var" && ..string.left(re1,1) != "_"){
				push(this.spTab,sp);
				push(this.epTab,ep);
				push(this.typeTab,"function");
				if(#re1 > 0 && #re2 == 0){
					push(this.nameTab,re1);
				}elseif(#re2 > 0 && re1 == 0){
					push(this.nameTab,re2);
				}
				if(#re3 == 0){
					push(this.argsTab,"null");
				}else{
					push(this.argsTab,re3);
				}
				if(re4 == "{"){
					push(this.blockMarkTab,re4);
				}elseif(#re4 == 0){
					push(this.blockMarkTab,"begin");
				}
				this.index++;
			}
		}while(ep && ep< strLen)		
	}
}