1.8 KiB
@function
Table of Contents
Syntax
FunctionRule ::= '@function' <ident-token> ArgumentDeclaration '{' Statements '}'
No whitespace is allowed between the Identifier
and the ArgumentDeclaration
in FunctionRule
.
Semantics
To execute a @function
rule rule
:
-
Let
name
be the value ofrule
'sIdentifier
. -
If
name
begins with--
, throw an error. -
If
name
iscalc
,element
,expression
,url
,and
,or
, ornot
, or ifname
has a vendor prefix and the unprefixed identifier is one of those strings, throw an error. -
Let
parent
be the current scope. -
Let
function
be a function namedname
which does the following when executed withargs
:-
With the current scope set to an empty scope with
parent
as its parent:-
Evaluate
args
withrule
'sArgumentDeclaration
. -
Execute each statement in
rule
. -
Return the value from the
@return
rule if one was executed, or throw an error if no@return
rule was executed.
-
-
-
If
rule
is outside of any block of statements:-
If
name
doesn't begin with-
or_
, set the current module's functionname
tofunction
.This overrides the previous definition, if one exists.
-
Set the current import context's function
name
tofunction
.This happens regardless of whether or not it begins with
-
or_
.
-
-
Otherwise, set the current scope's function
name
tofunction
.