Skip to content

Instantly share code, notes, and snippets.

joseoliv

Block or report user

Report or block joseoliv

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Number_bin.cyan
package metaobjectTest
@doc{*
This is a literal number annotation, an identifier follows a literal
number. The syntax for this annotation is
nbin or nBin or nBIN
in which 'n' is a literal number in base 2. 'n' can have numbers and
underscores but it should start with a number (otherwise the
compiler will consider it as an identifier). The metaobject uses method
View Number_base.cyan
package metaobjectTest
@doc{*
This is a literal number annotation, an identifier follows a literal
number. The syntax for this annotation is
n_base_N or n_BASE_N or n_Base_N
in which 'n' is a literal number in base 2 to 36 and N is the literal
number that is the base, in base 10. 'n' can have numbers, underscores, and letters
but, if it has letters, it should start with a number (otherwise the
View Printexpr.cyan
package metaobjectTest
@doc{*
Macro printexpr has the following syntax:
printexpr expr;
'printexpr' is a macro keyword and 'expr' is an expression. ';' should
end the macro call.
The macro call
View Assert.cyan
package metaobjectTest
@doc{*
Macro 'assert' has the following syntax:
assert expr;
'assert' is a macro keyword and 'expr' a Cyan expression. A ';'
should end the macro call.
At runtime, if 'expr' is false, an error message is issued.
The program is NOT terminated.
View Log.cyan
package metaobjectTest
@doc{*
Annotation 'log', when attached to a prototype P, without paramters,
adds a statement to each method 'm':
"Calling method 'm' of prototype 'P'" println
The same result is got by attaching 'log' to method 'm'
View String_n_N.cyan
package metaobjectTest
@doc{*
This is a literal string annotation, an identifier precedes a literal
string. In the string, escape characters are not considered.
The algorithm used for not-escaping the characters is not perfect.
It only considers letters such as \n and \r. An alternative to
this metaobject is to use triple quotes:
assert """\n""" == n"\n";
View String_r_R.cyan
package metaobjectTest
@doc{*
This is a literal string annotation, an identifier precedes a literal
string. The string should be a regular expression as expected by
prototype cyan.lang.RegExpr. The same regular expression language
is used by java.util.regex.Pattern. The annotation
r"regexpr" or R"regexpr"
is replaced by
View KeepValue.cyan
package metaobjectTest
@doc{*
Annotation 'doc' can be attached to any declaration, including
the program and packages
This metaobject generates code that writes to a file the value
of a local or field that is parameter to the annotation.
In fact, the last five values of the variable are kept in the file,
View InsertCode
package metaobjectTest
@doc{*
Annotation 'insertCode'
*}
object InsertCode
@insertCode{*
var Int n = 0;
View MyVector(2).cyan
package generic
object MyVector<T, V>
func init {
array = Array<T> new: @extract(V)
}
var Array<T> array
You can’t perform that action at this time.