Created
August 15, 2015 16:24
-
-
Save dwhitney/6fd6e0742dd8b75bd922 to your computer and use it in GitHub Desktop.
simple parser with parboiled2 that parses into a case class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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