Skip to content
← Back

src/syntax/trees/statements/function.ghul

1
namespace Syntax.Trees.Statements is
2
use Source
3
4
// A named function written among the statements of a function body.
5
// The name is a local of the enclosing body, defined from this
6
// statement onward, and the function itself is the literal that local
7
// is initialized with - so capture, emission and calling are an
8
// anonymous literal's throughout. The node exists so that what the
9
// source wrote survives: the formatter writes the named form back,
10
// and diagnostics anchor on the function rather than on a variable
11
// the user did not write.
12
class FUNCTION(location: LOCATION, name: Identifiers.Identifier, function: Expressions.FUNCTION): Statement is
13
variable: Variables.VARIABLE
14
15
// A `=>` body ends where the expression does, so its boundary
16
// needs a terminator, as an expression statement's does. An
17
// `is ... si` body carries its own, exactly as a compound
18
// statement does.
19
expects_semicolon: bool => !function.body.is_block
20
21
super(location)
22
23
init(..) is
24
variable =
25
Variables.VARIABLE(
26
location,
27
name,
28
TypeExpressions.INFER(name.location),
29
false,
30
false,
31
function
32
)
33
si
34
35
accept(visitor: Visitor) is
36
visitor.visit(self)
37
si
38
39
walk(visitor: Visitor) is
40
if !visitor.pre(self) then
41
variable.walk(visitor)
42
fi
43
44
accept(visitor)
45
si
46
si
47
si