Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
onMethodMissing
package metaobjectTest
@doc{*
Annotations of this metaobject should be attached to a prototype.
The attached DSL code is made in Myan, which supports interpreted Cyan
within parameterless methods declared with 'func':
func afti_codeToAdd {
// interpreted Cyan code
}
According to the method name, the Cyan code is interpreted in phase
afti or dsa. Methods of interfaces
IAction_dsa
IActionNewPrototypes_dsa
IAction_afti
IActionNewPrototypes_afti
IParseWithCyanCompiler_dpa
ICommunicateInPrototype_afti_dsa_afsa
IActionMethodMissing_dsa
can be implemented. To better understand this, see the documentation
for action_afti_dsa.
*}
@onMethodMissing{*
/* A method missing with two keywords and two parameters p1 and p2
is replaced by
p1 ++ p2 ++ p1
*/
func dsa_missingKeywordMethod {
var String sss0 = ((message getkeywordParameterList get: 0)
getExprList get: 0) asString;
var String sss1 = ((message getkeywordParameterList get: 1)
getExprList get: 0) asString;
var aType = env searchPackagePrototype: "cyan.lang", "String";
return [. sss0 ++ " ++ " ++ sss1 ++ " ++ " ++ sss0, aType .];
}
// a custom error message for unary message passings
// ending with 'Test'
func dsa_missingUnaryMethod {
var String name = unarySymbol getSymbolString;
if name endsWith: "Test" {
metaobject addError: "Methods ending with 'Test' have not been implemented yet";
}
}
*}
object OnMethodMissing
func run {
var ssss = self use: "abc" append: 0;
printexpr ssss;
assert ssss == "abc0abc";
// if uncommented, a compilation error with a custom error message
// self selfTest;
// if uncommented, a regular compilation error
// self alienMethod;
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.