Skip to content
← Back

src/syntax/parsers/definitions/namespace.ghul

1
namespace Syntax.Parsers.Definitions is
2
use Source
3
4
class NAMESPACE(
5
identifier_qualified_parser: Parser[Trees.Identifiers.Identifier],
6
definition_list_parser: Parser[Trees.Definitions.LIST]
7
): Base[Trees.Definitions.NAMESPACE] is
8
super()
9
10
parse(context: CONTEXT) -> Trees.Definitions.NAMESPACE? is
11
context.next_token(Lexical.TOKEN.NAMESPACE)
12
13
let start = context.location
14
let identifier = identifier_qualified_parser.parse(context)
15
16
if
17
identifier? /\
18
(context.current.token == Lexical.TOKEN.IS \/ !identifier.is_poisoned) /\
19
context.next_token(Lexical.TOKEN.IS)
20
then
21
let use open = context.open_construct(Lexical.TOKEN.SI)
22
23
context.namespace_depth = context.namespace_depth + 1
24
25
let body = definition_list_parser.parse(context)!
26
27
context.namespace_depth = context.namespace_depth - 1
28
29
let result =
30
Trees.Definitions.NAMESPACE(
31
start::context.location,
32
identifier,
33
body,
34
false
35
)
36
37
if !identifier.is_poisoned \/ context.current.token == Lexical.TOKEN.SI then
38
context.expect_closer(Lexical.TOKEN.SI)
39
fi
40
41
if identifier.is_poisoned then
42
result.poison()
43
fi
44
45
return result
46
fi
47
return null
48
si
49
si
50
si