package estivate.core.eval;

import estivate.core.ast.QueryAST;
import estivate.core.ast.parser.SelectQueryAST;
import estivate.core.eval.EstivateEvaluator.EvalContext;

public class SelectQueryEvaluator implements QueryASTEvaluator {

	public EvalContext eval(EvalContext context, QueryAST query) {
		SelectQueryAST select = (SelectQueryAST) query;
		
		EvalContext result = context.toBuilder().build();
		
		result.setDom(result.getDom().select(select.getQueryString()));
		
		return result;
	}

	public static QueryASTEvaluator.Factory factory = new Factory() {
		@Override
		public QueryASTEvaluator expressionEvaluater(QueryAST query) {
			if(query instanceof SelectQueryAST){
				return new SelectQueryEvaluator();
			}
			return super.expressionEvaluater(query);
		}
	};
	
}

@@ -24,16 +24,55 @@
 val;%0D%0A%0D%0A
+import org.jsoup.helper.StringUtil;%0D%0A%0D%0A
 import e
@@ -459,56 +459,182 @@
 %0D%0A%09%09
-result.setDom(result.getDom().select(select.getQ
+String queryString = select.getQueryString();%0D%0A%09%09if(StringUtil.isBlank(queryString))%7B%0D%0A%09%09%09result.setDom(result.getDom());%0D%0A%09%09%7Delse%7B%0D%0A%09%09%09result.setDom(result.getDom().select(q
 uery
@@ -643,15 +643,18 @@
 ring
-()
 ));%0D%0A
+%09%09%7D%0D%0A
 %09%09%0D%0A

fix selectQuery if queryString is empty