Warning

This section is not complete, and the specification has not been finalised.

10. Macros

10.1. Macro Invocation

syntax

MacroInvocation ::=
    # MacroInvocationHeader MacroSubject

MacroInvocationHeader ::=
    MacroName
    | [ MacroInvocations ]

MacroInvocations ::=
    MacroInvocationHeaderWithArgs (, MacroInvocationHeaderWithArgs)* ,?

MacroInvocationHeaderWithArgs ::=
    MacroName MacroInvocationArguments?

MacroName ::= Name

MacroInvocationArguments ::=
    ( ParameterList )

Examples

#[
  foreign_library("libfoo"),
  link_name("foo_create"),
  link_section(section="__text", segment="__text")
]
foo_create := () -> &raw Foo;

10.1.1. Macro Subjects

syntax

MacroSubject ::=
    Expression
    | Pattern
    | Type
    | EnumVariant
    | StructField
    | MatchArm
    | Parameter
    | TypeParameter

10.2. Token Macro Invocation

syntax

TokenMacroInvocation ::=
    @ TokenMacroInvocationHeader DelimitedTokenTree

TokenMacroInvocationHeader ::=
    TokenMacroName
    | [ TokenMacroName TokenMacroInvocationArguments? ]

TokenMacroName ::=
    Name

TokenMacroInvocationArguments ::=
    ( ParameterList )

DelimitedTokenTree ::=
    ( TokenTree* )
    | [ TokenTree* ]
    | { TokenTree* }

TokenTree ::=
    DelimitedTokenTree
    | NonDelimitedToken

10.2:1 A NonDelimitedToken is any lexical element in category LexicalElement, except the the category Delimiter.

Examples

sums := () => {
    min := @min {1 + 2, 3 * 4, 7 - 6 + 1 };
    max := @max {1 + 2, 3 * 4, 7 - 6 + 1 };

    if max - min == 0 {
        println("min and max are equal")
    } else {
        println("min and max are not equal")
    }
}



welcome := () => {
    @[xml(variant=html)] {
        <html>
            <head>
                <title>My page</title>
            </head>
            <body>
                <h1>Hello, world!</h1>
            </body>
        </html>
    }
}