Skip to content
← Back

src/syntax/parsers/definitions/variant_list.ghul

1
namespace Syntax.Parsers.Definitions is
2
use Source
3
use Logging
4
use Ghul.Disposable
5
6
class VARIANT_LIST(variant_parser: Parser[Trees.Definitions.VARIANT]): Base[Trees.Definitions.LIST] is
7
super()
8
9
parse(context: CONTEXT) -> Trees.Definitions.LIST is
10
let start = context.location
11
let should_poison mut = false
12
13
/*
14
parse a list of typed-union variants using the supplied variant parser
15
16
union_definition ::= "union" identifier type_parameters? modifiers? "is" variant_definition+ "si"
17
^ we're here
18
*/
19
20
try
21
let variants = Collections.LIST[Trees.Definitions.Definition]()
22
23
let start = context.location
24
let end mut = context.location
25
26
while context.current_token != Lexical.TOKEN.SI /\ context.current_token != Lexical.TOKEN.END_OF_INPUT do
27
let variant_start = context.location
28
29
let variant = variant_parser.parse(context)
30
31
if variant? then
32
variants.add(variant)
33
end = variant.location
34
else
35
end = context.location
36
fi
37
38
if !variant? \/ variant.is_poisoned then
39
should_poison = true
40
41
if variant_start.start_column <= context.member_indent \/ context.current_token != Lexical.TOKEN.IDENTIFIER then
42
// either indent is less than the member indent or we're not looking at an idenfier
43
// either way we've likely fallen off the end of the union definition:
44
45
if context.current_token == Lexical.TOKEN.SI then
46
context.next_token()
47
else
48
context.expect_closer(Lexical.TOKEN.SI)
49
fi
50
51
break
52
fi
53
fi
54
od
55
56
let result = Trees.Definitions.LIST(
57
start::end,
58
variants
59
)
60
61
62
result.poison(should_poison)
63
64
return result
65
finally
66
context.in_classy = false
67
yrt
68
si
69
si
70
si