Skip to content

Instantly share code, notes, and snippets.

@joseoliv
Last active August 30, 2022 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseoliv/26272ccc83dac4cee88b464d80f60b94 to your computer and use it in GitHub Desktop.
Save joseoliv/26272ccc83dac4cee88b464d80f60b94 to your computer and use it in GitHub Desktop.
onOverride_afterResTypes_semAn_afterSemAn
package metaobjectTest
@doc{*
Annotations of this metaobject should be attached to a method.
The attached DSL code is made in Myan, which supports interpreted Cyan
within parameterless methods declared with 'func':
func afterResTypes_codeToAdd {
// interpreted Cyan code
}
According to the method name, the Cyan code is interpreted in phase
afterResTypes or semAn. Methods of interfaces
IAction_semAn
IActionNewPrototypes_semAn
IAction_afterResTypes
IActionNewPrototypes_afterResTypes
IParseWithCyanCompiler_dpa
ICommunicateInPrototype_afterResTypes_semAn_afterSemAn
IActionMethodMissing_semAn
ICheckOverride_afterSemAn
can be implemented. To better understand this, see the documentation
for action_afterResTypes_semAn.
*}
open
object OnOverride_afterResTypes_semAn_afterSemAn
func run {
// a compilation warning with a custom error message
self selfTest;
// if uncommented, a regular compilation error
// self alienMethod;
}
@onOverride_afterResTypes_semAn_afterSemAn{*
// replace all keyword messages (without a declared method)
// with more than 3 keywords by 0
// Since this annotation is attached to a unary method,
// this method is not really used. Demonstration only.
func semAn_missingKeywordMethod {
let Int size = message getkeywordParameterList size;
if size > 3 {
var aType = env searchPackagePrototype: "cyan.lang", "Int";
return [. "0", aType .];
}
}
// an warning message for unary message passings
// ending with 'Test'
// It is necessary to return, in this case, an expression
// that replaces the message passing. Otherwise the
// compiler will issue an error
func semAn_missingUnaryMethod {
var String name = unarySymbol getSymbolString;
if name endsWith: "Test" {
Out println: "Methods ending with 'draw' have not been implemented yet";
return [. "JavaInterop nop", "cyan.lang", "Nil" .];
}
}
// only prototypes whose names start with 'Sub' can override
// this method. A message is printed, but no error is issued
func afterSemAn_checkOverride {
let String subProtoName = method getDeclaringObject getName;
let String methodName = method getName;
if !(subProtoName startsWith: "Sub") {
Out println: "I am really sorry, but method " ++
methodName ++ " can only be overridden in prototypes whose name " ++
"start with 'Sub'";
}
}
*}
func draw {
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment