Hi,
I switched from Java to Scala abour a month ago and just started using Parboiled for Scala yesterday so forgive me if there is a really easy solution to this ...
I have a file
Power: ON
Bat: 100%
GPRS: OFF
GPS: ON
ACC: OFF
Door: OFF
GSM: 19
Oil: 0.00%
APN: cmnet,,;
IP:
202.104.150.75:9000Arm: OFF
That Id like to view as a case class
I know I could read it into a Map but for my use case I dont want that solution.
sealed abstract class IResponse
case class StatusResponse(pwr: Boolean, bat:Float, gprs: Boolean, gps: Boolean, acc: Boolean, door: Boolean,
gsm: Int, oil:Float, apn:String, ip:String, arm:Boolean) extends IResponse
//Line 87
def Status: Rule1[StatusResponse] = rule { Pwr ~ Bat ~ Gprs ~ Gps ~ Acc ~ Door ~ Gsm ~ Oil ~ Apn ~ Ip ~ Arm } ~~> StatusResponse
def Pwr: Rule1[Boolean] = rule { ("Pwr"|"Power") ~ Separator ~ OnOff ~ optional(Space | EOL) }
def Door: Rule1[Boolean] = rule { "Door" ~ Separator ~ OnOff ~ optional(Space | EOL) }
def Acc: Rule1[Boolean] = rule { "ACC" ~ Separator ~ OnOff ~ optional(Space | EOL) }
def Gprs: Rule1[Boolean] = rule { "GPRS" ~ Separator ~ OnOff ~ optional(Space | EOL) }
def Gps: Rule1[Boolean] = rule { "GPS" ~ Separator ~ OnOff ~ optional(Space | EOL) }
def Arm: Rule1[Boolean] = rule { "Arm" ~ Separator ~ OnOff ~ optional(Space | EOL) }
def Bat: Rule1[Float] = rule { "Bat" ~ Separator ~ Real ~ ch('%') ~ optional(Space | EOL) }
def Gsm: Rule1[Int] = rule { "GSM" ~ Separator ~ Integer ~ optional(Space | EOL) }
def Oil: Rule1[Float] = rule { "Oil" ~ Separator ~ Real ~ ch('%') ~ optional(Space | EOL) }
def Apn: Rule1[String] = rule { str("APN:") ~ oneOrMore(noneOf("\n")) ~> {s=>s} ~ EOL }
def Ip: Rule1[String] = rule { str("IP:") ~ oneOrMore(noneOf("\n")) ~> {s=>s} ~ EOL}
Compiler Error
SmsParser2.scala:87: overloaded method value ~ with alternatives:
[GG >: Int, R](other: org.parboiled.scala.rules.ReductionRule1[GG,R])org.parboiled.scala.rules.Rule7[Boolean,Float,Boolean,Boolean,Boolean,Boolean,R] <and>
[FF >: Boolean, GG >: Int, R](other: org.parboiled.scala.rules.ReductionRule2[FF,GG,R])org.parboiled.scala.rules.Rule6[Boolean,Float,Boolean,Boolean,Boolean,R] <and>
[EE >: Boolean, FF >: Boolean, GG >: Int, R](other: org.parboiled.scala.rules.ReductionRule3[EE,FF,GG,R])org.parboiled.scala.rules.Rule5[Boolean,Float,Boolean,Boolean,R] <and>
[GG >: Int](other: org.parboiled.scala.rules.PopRule1[GG])org.parboiled.scala.rules.Rule6[Boolean,Float,Boolean,Boolean,Boolean,Boolean] <and>
[FF >: Boolean, GG >: Int](other: org.parboiled.scala.rules.PopRule2[FF,GG])org.parboiled.scala.rules.Rule5[Boolean,Float,Boolean,Boolean,Boolean] <and>
[EE >: Boolean, FF >: Boolean, GG >: Int](other: org.parboiled.scala.rules.PopRule3[EE,FF,GG])org.parboiled.scala.rules.Rule4[Boolean,Float,Boolean,Boolean] <and>
(other: org.parboiled.scala.rules.Rule0)org.parboiled.scala.rules.Rule7[Boolean,Float,Boolean,Boolean,Boolean,Boolean,Int]
cannot be applied to (org.parboiled.scala.Rule1[Float])
def Status: Rule1[StatusResponse] = rule { Pwr ~ Bat ~ Gprs ~ Gps ~ Acc ~ Door ~ Gsm ~ Oil ~ Apn ~ Ip ~ Arm } ~~> StatusResponse
^
one error found
Im stuck .... Any Ideas
Thanks in advance,
If you need the full file I can send it.