Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 groovy 扩展遗留脚本系统。源脚本是“类 java”,因此它主要解析为带有一点预处理的 groovy 脚本。
我正在使用 invokeMethod() 和 missingMethod() 来传递遗留代码,使我能够使用闭包和其他常规功能来增强脚本。但是,原始脚本使用“$foo”类型的字符串来引用变量。当missingMethod() 捕获到遗留方法时,我需要它不要将此字符串评估为GString,而只是逐字输出。这有可能吗?
有两种方法可以逃避 $foo:
例子:
def test = "bad" def s0 = "$test" def s1 = "\$test" assert s1 != s0 def s2 = '$test' assert s2 == s1 println s0 println s1 println s2
所以我想你必须使用你的预处理器来转义你的字符串