SHARE
TWEET

parser

a guest Apr 13th, 2012 37 Never
  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))
RAW Paste Data
Top