Skip to content

Annotations

apleshkov edited this page Aug 3, 2018 · 8 revisions

Saber uses annotations to get an info for building containers.

Simple rules to follow:

Only single-line comments

// @saber.scope(App)
struct A {}

// WRONG: 

/* @saber.scope(App) */
struct A {}

All annotations above

// @saber.scope(App)
class A {
    // @saber.inject
    var foo: Foo!
}

// WRONG: 

class A { // @saber.scope(App)    
    var foo: Foo! // @saber.inject
}

One annotation per line

// @saber.scope(App)
// @saber.cached
class A {}

// WRONG: 

// @saber.scope(App) @saber.cached
class A {}

// @saber.scope(App) Any text on the same line breaks parsing
class A {}

No line breaks between annotations and a declaration

// WRONG: all annotations will be ignored

// @saber.scope(App)
// @saber.cached

class A {}

// WRONG: scope will be ignored

// @saber.scope(App)

// @saber.cached
class A {}

// WRONG: scope will be ignored

// @saber.scope(App)
/*
Multiline comment with newlines
*/
class A {}

User comments

Multiline comments stop Saber parser, so place them above if needed. Any /* isn't recognizable, so it doesn't matter if there're newlines or not.

You can still use single-line comments everywhere.

/* User text 
 */
// @saber.scope(App)
// Also here
// @saber.cached
/// Or even here
class A {}

// WRONG:

// @saber.scope(App)
/* This line will stop the parser */
class A {}