// Path: src/main/java/org/dice/parsing/ast/Expression.java
// public interface Expression {
// 	public String evaluate();
// }
// 
// Path: src/main/java/org/dice/parsing/ast/operands/Operand.java
// public class Operand implements Expression {
// 	protected String value;
// 
// 	public Operand(String value) {
// 		this.value = value;
// 	}
// 
// 	public String evaluate() {
// 		return String.format("%s", value);
// 	}
// 
// 	@Override
// 	public String toString(){
// 		return this.evaluate();
// 	}
// }


import org.apache.commons.lang.StringUtils;
import org.dice.parsing.ast.Expression;
import org.dice.parsing.ast.operands.Operand;
import org.dice.parsing.ast.operators.*;
import java.util.HashSet;
import java.util.Set;

    private void sequenceExpression(){
        term();
        while (symbol == Lexer.TOKEN || symbol == Lexer.QUOTE || symbol == Lexer.FIELD) {
            Expression left = root;
            processTerminal();
            Expression right = root;
            root = new Or(left, right);
        }
    }

    private boolean isNotQuoteOrEOF(int symbol){
        return symbol != Lexer.QUOTE && symbol != Lexer.EOF;
    }

    private void quotedExpression() {
        StringBuilder quotedPhrase = new StringBuilder();
        // read all symbols (including boolean operators and parens) until a quote is reached.
        // if no quote reached, eat the rest of the expression as quoted phrase (what else can we do?)
        while(isNotQuoteOrEOF(symbol = lexer.nextSymbol())){
            // use just the string representations
            quotedPhrase.append(lexer.toString()).append(SPACE);
        }

        String phrase = quotedPhrase.toString().trim();
        if(StringUtils.isBlank(phrase)) {
            errors.add(ParserErrors.MissingQuoteCharacter.value);
        }
        // insert with empty string if needed (otherwise you have a hanging AND or OR
        // - (java AND "") is better than (java AND )
// Path: src/main/java/org/dice/parsing/ast/Expression.java
// public interface Expression {
// 	public String evaluate();
// }
// 
// Path: src/main/java/org/dice/parsing/ast/operands/Operand.java
// public class Operand implements Expression {
// 	protected String value;
// 
// 	public Operand(String value) {
// 		this.value = value;
// 	}
// 
// 	public String evaluate() {
// 		return String.format("%s", value);
// 	}
// 
// 	@Override
// 	public String toString(){
// 		return this.evaluate();
// 	}
// }


// Path: src/main/java/org/dice/parsing/RecursiveDescentParser.java
import org.apache.commons.lang.StringUtils;
import org.dice.parsing.ast.Expression;
import org.dice.parsing.ast.operands.Operand;
import org.dice.parsing.ast.operators.*;
import java.util.HashSet;
import java.util.Set;


    private void sequenceExpression(){
        term();
        while (symbol == Lexer.TOKEN || symbol == Lexer.QUOTE || symbol == Lexer.FIELD) {
            Expression left = root;
            processTerminal();
            Expression right = root;
            root = new Or(left, right);
        }
    }

    private boolean isNotQuoteOrEOF(int symbol){
        return symbol != Lexer.QUOTE && symbol != Lexer.EOF;
    }

    private void quotedExpression() {
        StringBuilder quotedPhrase = new StringBuilder();
        // read all symbols (including boolean operators and parens) until a quote is reached.
        // if no quote reached, eat the rest of the expression as quoted phrase (what else can we do?)
        while(isNotQuoteOrEOF(symbol = lexer.nextSymbol())){
            // use just the string representations
            quotedPhrase.append(lexer.toString()).append(SPACE);
        }

        String phrase = quotedPhrase.toString().trim();
        if(StringUtils.isBlank(phrase)) {
            errors.add(ParserErrors.MissingQuoteCharacter.value);
        }
        // insert with empty string if needed (otherwise you have a hanging AND or OR
        // - (java AND "") is better than (java AND )
        root = new Quote(new Operand(phrase));