Skip to content

Instantly share code, notes, and snippets.

@dwhitney
Created August 15, 2015 16:24
Show Gist options
  • Select an option

  • Save dwhitney/6fd6e0742dd8b75bd922 to your computer and use it in GitHub Desktop.

Select an option

Save dwhitney/6fd6e0742dd8b75bd922 to your computer and use it in GitHub Desktop.
simple parser with parboiled2 that parses into a case class
import org.parboiled2._
case class Person(name: String, age: Seq[Int])
//parses "dustin 35 36"
class PersonNumEvaluator(val input: ParserInput) extends Parser {
def InputLine = rule{ Both ~ EOI }
def Both = rule { Name ~ Number ~> Person }
def Name = rule { capture(oneOrMore(CharPredicate.Alpha)) }
def WS = rule { oneOrMore(" ") }
def Number = rule { zeroOrMore(WS ~ capture(oneOrMore(CharPredicate.Digit)) ~> (_.toInt)) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment