I am trying to write something like this : An andExpr is a orExpr separated by "and". If it not separated by "and" it should be taken as literal and not orExpr .
So, if I do :
def andExpr: Parser[Expr] = rep1sep(orExpr, "and") ^^{
//omitting the transformation function
} | literal
Lets assume every expression is an andExpr. I want an expression to be orExpr only if it is separated by "and". For example, if the input is "hello and hi", in this case "hello" is one orExpr and "hi" is one orExpr. But right now (the existing code I have written) every andExpr is an orExpr by default. So, right now if input is "bye", it is also an orExpr. But, I want "bye" to be qualified as literal and not orExpr.
How can I do this?
We can do it by using complex case statements.
For example :
def andExpr: Parser[Expr] = rep1sep(orExpr, "and") ^^{
case terms: if(terms.length == 1) {
terms.head . //treating like literal
} else {
//required expression
}
}