Skip to content

Instantly share code, notes, and snippets.

@karthik20522
Created May 25, 2019 06:49
Show Gist options
  • Save karthik20522/853fab15bee528a4c554365da27a2acb to your computer and use it in GitHub Desktop.
Save karthik20522/853fab15bee528a4c554365da27a2acb to your computer and use it in GitHub Desktop.
select age from users where age>30
def where: Parser[Where] = "where" ~> rep(predicate) ^^ (Where(_: _*))
def predicate = (
ident ~ "=" ~ wholeNumber ^^ { case f ~ "=" ~ i => NumberEquals(f, i.toInt) }
| ident ~ "<" ~ wholeNumber ^^ { case f ~ "<" ~ i => LessThan(f, i.toInt) }
| ident ~ ">" ~ wholeNumber ^^ { case f ~ ">" ~ i => GreaterThan(f, i.toInt) })
//output: GreaterThan("age", 30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment