Reputation: 462
I'm working on extending a legacy script system using groovy. The source scripts are "java-like", so it mostly parses as a groovy script with a little pre-processing.
I'm using invokeMethod() and missingMethod() to pass-through the legacy code, enabling me to use closures and other groovy features to enhance the scripts. However, the original script uses strings of the type "$foo" to refer to variables. When a legacy method is caught by missingMethod(), I need it to not evaluate this string as a GString, but simply outputting it verbatim. Is this possible in any way?
Upvotes: 4
Views: 3867
Reputation: 11062
there are two way to escape the $foo:
example:
def test = "bad"
def s0 = "$test"
def s1 = "\$test"
assert s1 != s0
def s2 = '$test'
assert s2 == s1
println s0
println s1
println s2
So I guess you have to use your preprocessor in order to escape your strings
Upvotes: 7