I am using a Scala parser as follows:
def a = b ~ c ^^ { case x ~ y => A(x,y) } def b = ... { B() } def c = ... { C() }
I now have a function change that changes when parsing a link previously parsed by B as val in C Therefore, the constructor C matters:
C(ref:B)
I can imagine the only way to achieve this is the dirty work of fixing it by assigning an instance of the parsed object B to def c between parsing a . Something like the 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 to do this? The definition of a cannot be violated; it is used in many places in the rest of the code.
Another solution is to use var instead of val and the following:
def a = (b ~ c ) ^^ { case x ~ y => y.ref = c ; A(x,y) }
But this is also unacceptable, since now it will "work", but in the future it will require additional efforts and boiler room code.
I have not tested this code, as this is a small part, and all changes require a lot of effort, so first you need to get an expert opinion.
source share