Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

parser

By: a guest on Apr 13th, 2012  |  syntax: Scala  |  size: 0.74 KB  |  views: 34  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. scala> import scala.util.parsing.combinator._
  2. import scala.util.parsing.combinator._
  3.  
  4. scala> object ExspessionParser extends JavaTokenParsers {
  5.      |   def parseExpr(e: String) = parseAll(expr, e)
  6.      |
  7.      |   def expr: Parser[Seq[(Double, Double)]] = "[" ~> repsep(pair, ",") <~ "]"
  8.      |   def pair: Parser[(Double, Double)] = "\"" ~> floatingPointNumber ~ "," ~ floatingPointNumber <~ "\"" ^^ {case a ~ b ~ c => (a.toDouble, c.toDouble) }
  9.      | }
  10. defined module ExspessionParser
  11.  
  12. scala> ExspessionParser.parseExpr("""["142.5,106.1","142.5,112.1","143.5,119.1","144.5,128.1","146.5,138.1","147.5,148.1"]""").get
  13. res11: Seq[(Double, Double)] = List((142.5,106.1), (142.5,112.1), (143.5,119.1), (144.5,128.1), (146.5,138.1), (147.5,148.1))
clone this paste RAW Paste Data