WeaselToken token = iterator.next();
if(Arrays.asList(end).contains(token.tokenType)){
if(generic!=null)
throw new WeaselCompilerException(token.line, "Expect Ident but got %s", token);
while(!tokenCache.isEmpty() && ((Properties)tokenCache.get(0).param).suffix!=null){
tokenSuffix.add(tokenCache.remove(0));
}
if(tokenCache.size()!=0){
throw new WeaselCompilerException(token.line, "Expect suffix but got %s", tokenCache.get(0));
}
if(!tokenSuffix.isEmpty()){
WeaselTreeAddResult wtar = bottom.add(tokenSuffix, null, null, null, iterator);
bottom = wtar.newTree;
}
tokenPrefix.clear();
tokenSuffix.clear();
tokenCache.clear();
break;
}else{
if(token.tokenType==WeaselTokenType.KEYWORD && token.param==WeaselKeyWord.INSTANCEOF){
WeaselToken t = iterator.next();
WeaselCompiler.expect(t, WeaselTokenType.IDENT);
String className = (String)t.param;
t = iterator.next();
while(t.tokenType==WeaselTokenType.OPERATOR && t.param==WeaselOperator.ELEMENT){
t = iterator.next();
WeaselCompiler.expect(t, WeaselTokenType.IDENT);
className += "."+(String)t.param;
t = iterator.next();
}
if(t.tokenType==WeaselTokenType.OPERATOR && t.param==WeaselOperator.LESS){
generic = new WeaselTreeGeneric(iterator);
if(generic.close)
throw new WeaselCompilerException(t.line, "To many >");
}else{
iterator.previous();
}
token = new WeaselInstanceofToken(token.line, className, generic);
generic = null;
}
if(token.tokenType==WeaselTokenType.COMMA){
token = new WeaselToken(WeaselTokenType.OPERATOR, token.line, WeaselOperator.COMMA);
}
if(token.tokenType==WeaselTokenType.QUESTIONMARK){
if(generic!=null)
throw new WeaselCompilerException(token.line, "Expect Ident but got ?:");
while(!tokenCache.isEmpty() && ((Properties)tokenCache.get(0).param).suffix!=null){
tokenSuffix.add(tokenCache.remove(0));
}
if(tokenCache.size()!=0){
throw new WeaselCompilerException(token.line, "Expect suffix but got %s", tokenCache.get(0));
}
if(!tokenSuffix.isEmpty()){
WeaselTreeAddResult wtar = bottom.add(tokenSuffix, null, null, null, iterator);
bottom = wtar.newTree;
}
WeaselTree tree = parse(iterator, WeaselTokenType.COLON);
WeaselTreeCondition wtc = new WeaselTreeCondition(tree, token);
WeaselTreeAddResult wtar = wtc.setLeft(bottom);
bottom = wtar.newTree;
start = true;
}else if(token.tokenType == WeaselTokenType.OPERATOR){
if(generic!=null)
throw new WeaselCompilerException(token.line, "Expect Ident but got %s", token);
tokenCache.add(token);
if(token.param == WeaselOperator.ELEMENT){
WeaselToken wtoken = iterator.next();
if(wtoken.tokenType == WeaselTokenType.OPERATOR && wtoken.param ==WeaselOperator.LESS) {
generic = new WeaselTreeGeneric(iterator);
token = iterator.previous();
if(generic.close){
throw new WeaselCompilerException(token.line, "Expect Ident but got >");
}
}else{
iterator.previous();
}
}
}else{
if(generic!=null && token.tokenType != WeaselTokenType.IDENT)
throw new WeaselCompilerException(token.line, "Expect ident after generic but got %s", token);
boolean isCast = false;
if(token.tokenType==WeaselTokenType.OPENBRACKET){
WeaselToken token2 = iterator.next();
String className = "";
if(token2.tokenType==WeaselTokenType.IDENT){
isCast = true;
className = (String)token2.param;
token2 = iterator.next();
while(token2.tokenType==WeaselTokenType.OPERATOR && token2.param == WeaselOperator.ELEMENT){
token2 = iterator.next();
if(token2.tokenType!=WeaselTokenType.IDENT){
isCast = false;
break;
}
className += "."+(String)token2.param;
token2 = iterator.next();
}
if(token2.tokenType==WeaselTokenType.OPERATOR && token2.param == WeaselOperator.LESS){
try{
generic = new WeaselTreeGeneric(iterator);
token2 = iterator.next();
}catch(WeaselCompilerException e){
isCast = false;
}
}
if(isCast && token2.tokenType!=WeaselTokenType.CLOSEBRACKET){
isCast = false;
}
}
if(isCast){
tokenCache.add(new WeaselCastToken(token.line, className, generic));
}else{
while(iterator.previous() != token);
iterator.next();
}
generic = null;
}
if(!isCast){
if(start){
while(!tokenCache.isEmpty() && ((Properties)tokenCache.get(tokenCache.size()-1).param).prefix!=null){
tokenPrefix.add(tokenCache.remove(tokenCache.size()-1));
}
if(!tokenCache.isEmpty()){
throw new WeaselCompilerException(token.line, "Expect prefix but got %s", tokenCache.get(0));
}
if(token.tokenType==WeaselTokenType.OPENBRACKET){
WeaselTree add = parse(iterator, WeaselTokenType.CLOSEBRACKET);
if(tokenPrefix.isEmpty()){
if(bottom==null){
bottom = new WeaselTreeTop(add, iterator);
}else{
bottom.add(null, null, null, new WeaselTreeTop(add, iterator), iterator);
}
}else{
if(bottom==null){
bottom = new WeaselTreeLevel(((Properties)tokenPrefix.get(0).param).priority);
}
WeaselTreeAddResult wtar = bottom.add(null, null, tokenPrefix, add, iterator);
bottom = wtar.newTree;
}
}else{
WeaselTree add = new WeaselTreeTop(token, null, iterator);
if(tokenPrefix.isEmpty()){
if(bottom==null){
bottom = add;
}else{
bottom.add(null, null, null, add, iterator);
}
}else{
if(bottom==null){
bottom = new WeaselTreeLevel(((Properties)tokenPrefix.get(0).param).priority);
}
WeaselTreeAddResult wtar = bottom.add(null, null, tokenPrefix, add, iterator);
bottom = wtar.newTree;
}
}
tokenPrefix.clear();
tokenSuffix.clear();
tokenCache.clear();
start = false;
}else{
if(tokenCache.size()==0){
throw new WeaselCompilerException(token.line, "Expect %s before %s", Arrays.toString(end), token);
}
while(!tokenCache.isEmpty() && ((Properties)tokenCache.get(0).param).suffix!=null){
tokenSuffix.add(tokenCache.remove(0));
}
if(tokenCache.isEmpty() && !tokenPrefix.isEmpty()){
while(true){
tokenCache.add(0, tokenPrefix.remove(tokenPrefix.size()-1));
if(((Properties)tokenCache.get(0).param).infix!=null){
break;
}
}
}
while(tokenCache.size()>1 && ((Properties)tokenCache.get(tokenCache.size()-1).param).prefix!=null){
tokenPrefix.add(0, tokenCache.remove(tokenCache.size()-1));
}
if(tokenCache.size()==0){
throw new WeaselCompilerException(token.line, "Expect %s before %s", Arrays.toString(end), token);
}
if(tokenCache.size()>1){
throw new WeaselCompilerException(tokenCache.get(1).line, "Expect suffix or variable but got %s", tokenCache.get(1));
}
for(WeaselToken token1:tokenSuffix){
token1.param = ((Properties)token1.param).suffix;
if(token1.param==null)