Skip to content

Instantly share code, notes, and snippets.

@joseoliv
Last active June 25, 2019 03:49
Show Gist options
  • Save joseoliv/b23083b3f301ac5dc403bc11624a2e3d to your computer and use it in GitHub Desktop.
Save joseoliv/b23083b3f301ac5dc403bc11624a2e3d to your computer and use it in GitHub Desktop.
setVariable
package metaobjectTest
@doc{*
Annotation 'setVariable' can be attached to the program or a package.
It takes two parameters, a key and a value, and associates the
program or package key to the value. If the attached annotation is
the program, the value can be got from method
Object getProgramValueFromKey(String key)
of WrProgram. If the attached annotation is a package, the value can
be got from method
Object getPackageValueFromKey(String key)
Or one can use annotation getProgramValueFromKey that takes a key
as parameter and produces a string with the contents of the
value corresponding to the key in the *program*. Or, if the key is not valid,
"". Annotation getPackageValueFromKey takes a key as parameter
and produces a string with the contents of the value of the key
in the *package*.
*}
object SetVariable
func run {
/*
The project file, p.pyan, has the contents
@setVariable(debug, "yes")
@setVariable(author, "Jose")
// elided
program
// elided
@setVariable(test, create)
@setVariable(goal, "Test all metaobjects")
package metaobjectTest
// elided
Therefore the program variable 'debug' is associated
to "yes" and 'author' to "Jose".
The package variable 'test' is associated to
"create" (even without the quotes) and 'goal' to
"Test all metaobjects"
Annotation @getProgramValueFromKey(debug) is
an expression that is "" if 'debug' is not
a key or the value associated to it. Since 'debug'
was set to "yes", to variable 'value' is assigned
"yes" at the program runtime.
*/
var String value = @getProgramValueFromKey(debug);
assert value == "yes";
value = @getProgramValueFromKey(author);
assert value == "Jose";
value = @getPackageValueFromKey(test);
assert value == "create";
value = @getPackageValueFromKey(goal);
assert value == "Test all metaobjects";
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment