Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
onDeclaration_afti_dsa_afsa
package metaobjectTest
@doc{*
Annotations of this metaobject are attached to a declaration.
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, dsa, or afsa. Methods of interfaces
IAction_dsa
IActionNewPrototypes_dsa
IAction_afti
IActionNewPrototypes_afti
IParseWithCyanCompiler_dpa
ICommunicateInPrototype_afti_dsa_afsa
ICheckDeclaration_afsa
can be implemented. To better understand this, see the documentation
for action_afti_dsa.
*}
object OnDeclaration_afti_dsa_afsa
func run {
assert get_age == 0;
age = 12;
assert get_age == 12;
assert get_name == "";
}
/*
Method get_name is added to the prototype
*/
@onDeclaration_afti_dsa_afsa{*
func afsa_checkDeclaration {
var annotation = metaobject getMetaobjectAnnotation;
var String name = annotation getDeclaration getName;
if name != "age" {
metaobject addError: "Field name should be 'age'"
}
}
func afti_codeToAdd {
var annotation = metaobject getMetaobjectAnnotation;
var String name = annotation getDeclaration getName;
var String typeName = annotation getDeclaration getType getName;
return [. "func get_" ++ name ++ " -> " ++ typeName ++
" = " ++ name ++ ";", "func get_" ++ name ++ " -> Int" .]
}
*}
var Int age = 0;
// method get_name is added to the prototype
@onDeclaration_afti_dsa_afsa{*
func afti_codeToAdd {
var annotation = metaobject getMetaobjectAnnotation;
var String name = annotation getDeclaration getName;
var String typeName = annotation getDeclaration getType getName;
return [. "func get_" ++ name ++ " -> " ++ typeName ++
" = " ++ name ++ ";",
"func get_" ++ name ++ " -> " ++ typeName .]
}
*}
var String name = "";
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.