parsing - passing value down the pipe in Scala parser combinator -
i have following rules (many others obmitted clarity):
def bindrg: parser[cmd] = "bind-roaming-group" ~> name ~ bindrgbody(????) <~ exit ^^ { case name~body => new bindroaminggroupcmd(name, body)} def bindrgbody(name: string) = // ... def name: parser[string] = """\s+""".r
i want pass string value of "name" bindrgbody(????) not sure put in '????'
you use flatmap
on parser "bind-roaming-group" ~> name
:
def bindrg: parser[cmd] = ("bind-roaming-group" ~> name) flatmap (n => bindrgbody(n) <~ exit ^^ (b => new bindroaminggroupcmd(n, b)))
or
def bindrg: parser[cmd] = ("bind-roaming-group" ~> name) >> (n => bindrgbody(n) <~ exit ^^ (new bindroaminggroupcmd(n, _)))
if want shorten bit.
Comments
Post a Comment