preProcessor-receiver

I have a little language for live coding made with preProcessor that splits the incoming code and reconstructs it as receiver.method(args). Inside the preProcessor i analyze the code using regexp etc to set these three variables and finally format the string into valid sc code like this:

"%.%(%)".format(receiver, method, args);

I wrote the preProcessor as a class that has an argument for the receving object. However, since the preProcessor returns code that is interpreted outside of the class’ scope the only solution i could think of was to use an environment variable for the receiver. This feels a bit unsafe to me. Is there a better way?

This is (sort of) how i do it now:

MyPreProcessor {
	*run {|aReceivingObject|
		~receivingObject = aReceivingObject;
		thisProcess.interpreter.preProcessor = {|code|
			code.split($\n).collect{|line|
				var receiver, method, args;
				receiver = "~receivingObject";
				method = line.findRegexp(...).do{|match| ...};
				args = line.findRegexp(...).do{|match| ...};
				"%.%(%)".format(receiver, method, args);
			}.join;
		};
	}
}

since there is only one preprocessor active at a given time, why not use a class variable to store and retrieve the current receiving object ?

You mean a getter classvar? Better than environment variable, yes. But it’s still not encapsulated, right? Maybe there’s no way of doing this within the scope of the class when working with preProcessor?