Skip to content

Instantly share code, notes, and snippets.

@karthik20522
Created May 25, 2019 06:48
Show Gist options
  • Save karthik20522/8d7e569d10f8b43e5675bc7be3ccf1ab to your computer and use it in GitHub Desktop.
Save karthik20522/8d7e569d10f8b43e5675bc7be3ccf1ab to your computer and use it in GitHub Desktop.
select * from users order by name, age desc
abstract class Direction
case class Asc(field: String*) extends Direction
case class Desc(field: String*) extends Direction
def order: Parser[Direction] = {
("order" ~> "by" ~> ident ~ ("asc" | "desc") ^^ {
case f ~ "asc" => Asc(f)
case f ~ "desc" => Desc(f)
}) | ("order" ~> "by" ~> repsep(ident, ",") ~ ("asc" | "desc") ^^ {
case f ~ "asc" => Asc(f: _*)
case f ~ "desc" => Desc(f: _*)
})
}
//output: Desc("name", "age")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment