Skip to content
← Back

src/semantic/symbols/tuple.ghul

1
namespace Semantic.Symbols is
2
use Collections.List;
3
4
use IO.Std;
5
6
use IoC;
7
use Logging;
8
use Source;
9
10
use Types.Type;
11
12
use Ghul.Pipes;
13
14
class TUPLE: GENERIC is
15
names: List[string?]?;
16
17
qualified_name: string => Types.TUPLE.get_short_description(type, names);
18
19
describe(context: DESCRIBE_CONTEXT) -> SignaturePart =>
20
PARTS.literal(qualified_name);
21
22
init(location: LOCATION, symbol: Symbols.Classy, arguments: Collections.List[Type], names: List[string?]?) is
23
super.init(location, symbol, arguments);
24
25
self.names = names;
26
si
27
28
get_element_name(index: int) -> string? =>
29
if names? /\ index < names.count then
30
names[index]
31
else
32
"{index}"
33
fi;
34
35
find_named_element(name: string) -> Symbol? is
36
if !names? then
37
return null;
38
fi
39
40
let m = names |> index() |> find(iv => iv.value =~ name);
41
42
if !m? then
43
return null;
44
fi
45
46
let s = symbol.find_direct("{m.index}");
47
return _specialize(s);
48
si
49
50
find_direct(name: string) -> Symbol? is
51
assert_symbols_pulled_down();
52
53
return _specialize(symbol.find_direct(name));
54
si
55
56
find_member(name: string) -> Symbol? is
57
let named_element = find_named_element(name);
58
59
if named_element? then
60
return named_element;
61
fi
62
63
return _specialize(symbol.find_member(name));
64
si
65
66
find_enclosing(name: string) -> Symbol? is
67
let unspecialized = symbol.find_enclosing(name);
68
69
if unspecialized? /\ unspecialized.owner == symbol then
70
return _specialize(unspecialized);
71
else
72
return unspecialized;
73
fi
74
si
75
76
find_direct_matches(prefix: string, matches: Collections.MutableMap[string, Symbols.Symbol]) is
77
let m = Collections.MAP[string, Symbols.Symbol]();
78
79
symbol.find_direct_matches(prefix, m);
80
81
if names? then
82
for (index, name) in names |> index() do
83
if name? then
84
if let positional = symbol.find_direct("{index}") then
85
m[name] = positional;
86
fi
87
m.remove("{index}");
88
fi
89
od
90
fi
91
92
for p in m do
93
if !matches.contains_key(p.key) then
94
matches[p.key] = _specialize(p.value)!.collapse_group_if_single_member();
95
fi
96
od
97
si
98
99
find_member_matches(prefix: string, matches: Collections.MutableMap[string, Symbols.Symbol]) is
100
find_direct_matches(prefix, matches);
101
symbol.find_ancestor_matches(prefix, matches);
102
si
103
104
find_enclosing_matches(prefix: string, matches: Collections.MutableMap[string, Symbols.Symbol]) is
105
si
106
107
to_string() -> string => description;
108
si
109
si