Appearance
| 1 | namespace Syntax.Trees.Identifiers is | |
| 2 | use IO.Std; | |
| 3 | ||
| 4 | use Source; | |
| 5 | ||
| 6 | // Constructed, so UPPER_SNAKE_CASE by convention, but the | |
| 7 | // UPPER_SNAKE_CASE name IDENTIFIER is already taken by | |
| 8 | // Trees.Expressions.IDENTIFIER, which many files reference | |
| 9 | // unqualified alongside this namespace. | |
| 10 | @suppress("non-upper-snake-case-name") | |
| 11 | class Identifier(location: LOCATION, name: string mut): Trees.Node, Collections.Iterable[string] is | |
| 12 | name: string public; | |
| 13 | ||
| 14 | qualifier: Identifier? => null; | |
| 15 | ||
| 16 | qualifier_names: Collections.LIST[string] => Collections.LIST[string](0); | |
| 17 | ||
| 18 | names: Collections.LIST[string] => Collections.LIST[string]([name]); // : string; | |
| 19 | ||
| 20 | is_qualified: bool => false; | |
| 21 | ||
| 22 | right_location: LOCATION => location; | |
| 23 | ||
| 24 | iterator: Collections.Iterator[string] => names.iterator; | |
| 25 | ||
| 26 | super(location); | |
| 27 | ||
| 28 | init(..) is | |
| 29 | if name == null then | |
| 30 | poison(); | |
| 31 | self.name = "$poisoned"; | |
| 32 | fi | |
| 33 | si | |
| 34 | ||
| 35 | copy() -> Identifier => | |
| 36 | Identifier(location, name); | |
| 37 | ||
| 38 | copy_as_expression() -> Expressions.Expression is | |
| 39 | if let self.qualifier? then | |
| 40 | return Expressions.MEMBER(location, qualifier.copy_as_expression(), Identifier(right_location, name), right_location); | |
| 41 | else | |
| 42 | return Expressions.IDENTIFIER(location, self.copy()); | |
| 43 | fi | |
| 44 | si | |
| 45 | ||
| 46 | accept(visitor: Visitor) is | |
| 47 | visitor.visit(self); | |
| 48 | si | |
| 49 | si | |
| 50 | ||
| 51 | class QUALIFIED( | |
| 52 | location: LOCATION, | |
| 53 | _qualifier: Identifier, | |
| 54 | name: string, | |
| 55 | completion_target: LOCATION, | |
| 56 | right_location: LOCATION | |
| 57 | ): Identifier is | |
| 58 | is_qualified: bool => true; | |
| 59 | ||
| 60 | qualifier: Identifier => _qualifier; | |
| 61 | ||
| 62 | qualifier_names: Collections.LIST[string] is | |
| 63 | let result = Collections.LIST[string](); | |
| 64 | let p: Identifier? mut = qualifier; | |
| 65 | ||
| 66 | while p? do | |
| 67 | result.add(p.name); | |
| 68 | p = p.qualifier; | |
| 69 | od | |
| 70 | ||
| 71 | return result; | |
| 72 | si | |
| 73 | ||
| 74 | names: Collections.LIST[string] is | |
| 75 | let result = Collections.LIST[string](); | |
| 76 | ||
| 77 | result.add(name); | |
| 78 | ||
| 79 | let p: Identifier? mut = qualifier; | |
| 80 | ||
| 81 | while p? do | |
| 82 | result.add(p.name); | |
| 83 | p = p.qualifier; | |
| 84 | od | |
| 85 | ||
| 86 | return result; | |
| 87 | si | |
| 88 | ||
| 89 | iterator: Collections.Iterator[string] is | |
| 90 | let result = Collections.LIST[string](); | |
| 91 | ||
| 92 | result.add(name); | |
| 93 | ||
| 94 | let p: Identifier? mut = qualifier; | |
| 95 | ||
| 96 | while p? do | |
| 97 | result.add(p.name); | |
| 98 | p = p.qualifier; | |
| 99 | od | |
| 100 | ||
| 101 | return result.iterator; | |
| 102 | si | |
| 103 | ||
| 104 | super(location, name); | |
| 105 | ||
| 106 | init(..) is | |
| 107 | poison(qualifier.is_poisoned); | |
| 108 | si | |
| 109 | ||
| 110 | copy() -> Identifier is | |
| 111 | let np = qualifier.copy(); | |
| 112 | ||
| 113 | return QUALIFIED( | |
| 114 | location, | |
| 115 | np, | |
| 116 | name, | |
| 117 | completion_target, | |
| 118 | right_location | |
| 119 | ); | |
| 120 | si | |
| 121 | ||
| 122 | accept(visitor: Visitor) is | |
| 123 | visitor.visit(self); | |
| 124 | si | |
| 125 | ||
| 126 | walk(visitor: Visitor) is | |
| 127 | if !visitor.pre(self) then | |
| 128 | qualifier.walk(visitor); | |
| 129 | fi | |
| 130 | ||
| 131 | accept(visitor); | |
| 132 | si | |
| 133 | si | |
| 134 | si |