Sequence of 7+ items gives an error mentioning org.parboiled.scala.rules.Rule7 is 7 the max?

15 views
Skip to first unread message

Andrew Bailey

unread,
Mar 14, 2018, 4:47:47 AM3/14/18
to parboiled2.org User List
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:9000
Arm: 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.

Andrew Bailey

unread,
Mar 14, 2018, 10:06:26 AM3/14/18
to parboiled2.org User List
Hi all,

Problem solved, I actually thought I was using parboiled 2 however I discovered that it was parboiled 1, I changed over and problem solved .

Sorry for that.

:)

Mathias Doenitz

unread,
Mar 14, 2018, 10:27:18 AM3/14/18
to parboil...@googlegroups.com
Glad you sorted things out!

Cheers,
Mathias

---
mat...@parboiled.org
http://www.parboiled.org
> --
> You received this message because you are subscribed to the Google Groups "parboiled2.org User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to parboiled-use...@googlegroups.com.
> Visit this group at https://groups.google.com/group/parboiled-user.
> To view this discussion on the web visit https://groups.google.com/d/msgid/parboiled-user/ac8390ea-2354-4590-b252-cff8bcf1f2f2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages