I writing a DSL that executes as a Script; it has various classes for various bits of syntax. e.g., for the “foo” keyword that takes a closure, I have a FooSyntax class and evaluate the closure “with” an instance of that syntax. This works fine, e.g.
bar = thing {} // make a thing
baz = foo {
mykeyword bar
}
passes the thing called bar to an invocation of FooSyntax#mykeyword.
I’m trying to add some better error messages for when there is an unknown variable reference. This manifests as a MissingPropertyException so my current approach is to add a propertyMissing method to FooSyntax. This works indeed for variables that are missing.
Unfortunately, it breaks the example above: bar becomes a missing property instead of falling through to the Binding. Why does adding a propertyMissing cause the Binding not to be consulted? (Does this have to do with the Closure‘s resolve strategy?) How can I fix this?
You can play with this with a sample script at https://gist.github.com/1237768
I shall delegate my answer to the gist on which I commented. Basically, you should not be using the
with()method to execute the closure against theFooSyntaxdelegate. For future reference, the standard approach is:You can fine tune the behaviour by changing the resolution strategy on the closure like so:
but in this case you want the default
Closure.OWNER_FIRSTto ensure the binding is queried first.