I am using Scala's combinator parser as follows:
def a = b ~ c ^^ { case x ~ y => A(x,y) }
def b = ... { B() }
def c = ... { C() }
now I have a feature change that change within the parsing of the reference of previously parsed B
to be a val
in C
. So C
's constructor is something like:
C(ref:B)
I can imagine, the only way to achieve this is a dirty patch work by assigning the instance of parsed B
object to def c
in between the parsing of a
. Something like following:
var temp:B = null
def a = ( b ^^ { case x => temp = x } )
~ c(temp) ^^ {case x ~ y => A(x,y} )
Is there a standard, clean way of doing this? The definition of a
can't be broken, it is used in many places in rest of the code.
The other solution is to use var
instead of val
and have following:
def a = (b ~ c ) ^^ { case x ~ y => y.ref = c ; A(x,y) }
But this is also not acceptable as it would "work" now, but it would involve extra effort and boiler-plate code in future development.
I've not tested this code, as this is a small part and all the changes require a lot of effort so want the expert opinion first.