Skip to content

Instantly share code, notes, and snippets.

View joseoliv's full-sized avatar

José de Oliveira Guimarães joseoliv

View GitHub Profile
@joseoliv
joseoliv / OnOverride_afterResTypes_semAn_afterSemAn.cyan
Last active August 30, 2022 11:42
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
@joseoliv
joseoliv / OnFieldMissing.cyan
Last active August 30, 2022 11:22
onFieldMissing
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 afterResTypes_codeToAdd {
// interpreted Cyan code
@joseoliv
joseoliv / OnFieldAccess.cyan
Last active August 30, 2022 11:21
onFieldAccess
package metaobjectTest
@doc{*
Annotations of this metaobject are attached to a field.
The attached DSL code is made in Myan, which supports interpreted Cyan
within parameterless methods declared with 'func':
func afterResTypes_codeToAdd {
// interpreted Cyan code
@joseoliv
joseoliv / OnDeclaration_afterResTypes_semAn_afterSemAn.cyan
Last active August 30, 2022 11:20
OnDeclaration_afterResTypes_semAn_afterSemAn
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 afterResTypes_codeToAdd {
// interpreted Cyan code
@joseoliv
joseoliv / AddMethodTo.cyan
Last active August 30, 2022 08:17
Metaobject addMethodTo
package metaobjectTest
@addMethodTo("func zero -> Int", "func zero -> Int = 0;")
@addMethodTo(
"""func len: String s less: Int -> Int""",
"""
func len: String s less: Int n -> Int { return s size - n}
""")
object AddMethodTo
@joseoliv
joseoliv / AddFieldInfo.cyan
Last active August 30, 2022 08:16
add information on fields
package metaobjectTest
@doc{*
addFieldInfo takes two parameters. The first is an identifier id.
The second can be either 'counter' or 'names'. If it is 'counter',
the metaobject creates a field
let Int id = number of fields in the prototype;
and a method
func counter_id -> Int = number of methods in the prototype;
@joseoliv
joseoliv / AddCodeFromMetaobject.cyan
Last active August 30, 2022 08:15
Metaobjects addCodeToGenericPrototype and AddCodeFromMetaobject
package metaobjectTest
/*
@addCodeFromMetaobject is in prototype Array. The annotation
addCodeToGenericPrototype gives the code to be added to the
array of prototype AddCodeFromMetaobject.
*/
@addCodeToGenericPrototype("Array", " func sumAll -> Int"){*
@joseoliv
joseoliv / Action_afterResTypes_semAn.cyan
Last active August 30, 2022 08:14
metaobject action_afti_dsa
package metaobjectTest
// @doc{+* is used instead of @doc{* because '{*' is used
// in the text attached to @doc
@doc{+*
This metaobject can add fields and methods to the current prototype,
add code before methods, and add code inside methods (if the annotation
is inside a method). This text is in language Markdown. Unlike other
metaobjects, this one demands the understanding of the Cyan Metaobject
@joseoliv
joseoliv / RestrictTo
Last active April 24, 2021 07:23
restrict the values a variable can hold
package metaobjectTest
@doc{*
Annotation 'type' should be attached to a type. It checks whether
the value of the type obeys the expression that is attached to
the annotation. Use 'self' as the value of the object that is
being restricted. Therefore, the expressions can be something like:
self >= 0
self >= 0 && self < 5
@joseoliv
joseoliv / FSM_DSL_Methods.cyan
Last active April 24, 2021 05:20
fsmDSLMethods
package metaobjectTest
@doc{*
Annotation 'fsmMethod' should be attached to a prototype. The parameter
name is optional. If present, it should be an identifer. The metaobject
creates a reset method with name 'resetFSM_Methods' or with the name
of the parameter. This method resets the FSM to the initial state.
q0, "q0q0:1" -> q0