Skip to content
← Back

src/syntax/process/tuple_element_name.ghul

1
namespace Syntax.Process is
2
// Pure rule for inferring the tuple-literal element name from a
3
// bare-identifier element. When the identifier resolves to a
4
// field whose name starts with a single underscore (the
5
// private-member naming convention), the underscore is stripped
6
// so that a tuple packed from private fields exposes the
7
// underlying names to consumers without leaking the prefix.
8
//
9
// The rule lives outside COMPILE_TUPLES so its corner cases
10
// (locals not stripped, double-underscore not stripped, a bare
11
// single underscore not stripped) can be pinned by unit tests
12
// without standing up the full visitor.
13
class TUPLE_ELEMENT_NAME is
14
infer(identifier_name: string, is_field_symbol: bool) -> string static is
15
if
16
is_field_symbol /\
17
identifier_name.length > 1 /\
18
identifier_name.starts_with('_') /\
19
!identifier_name.starts_with("__")
20
then
21
return identifier_name.substring(1);
22
fi
23
24
return identifier_name;
25
si
26
si
27
si