Appearance
| 1 | namespace Syntax.Process is | |
| 2 | use Source; | |
| 3 | use Trees; | |
| 4 | ||
| 5 | // Walks a source file's AST and records the source location of every | |
| 6 | // contextual-keyword modifier — currently `init` and `open`. A later | |
| 7 | // rewrite pass consumes primary-ctor `init` modifiers and clears the | |
| 8 | // param list, so the locations are captured here, at post-parse, and | |
| 9 | // stashed on the source file for the analysis-mode semantic-tokens | |
| 10 | // handler to consume. | |
| 11 | // | |
| 12 | // `abstract` is a hard keyword and lit by the TextMate grammar; | |
| 13 | // `public`/`static`/… are hard keywords too. Only contextually-lexed | |
| 14 | // modifiers need the semantic-token overlay. | |
| 15 | class COLLECT_MODIFIER_KEYWORD_LOCATIONS: Visitor is | |
| 16 | _locations: Collections.LIST[LOCATION]; | |
| 17 | ||
| 18 | init() is | |
| 19 | super.init(); | |
| 20 | ||
| 21 | _locations = Collections.LIST[LOCATION](); | |
| 22 | si | |
| 23 | ||
| 24 | apply(source_file: Compiler.SOURCE_FILE) is | |
| 25 | _locations = Collections.LIST[LOCATION](); | |
| 26 | ||
| 27 | source_file.definition.walk(self); | |
| 28 | ||
| 29 | source_file.contextual_modifier_locations = _locations; | |
| 30 | si | |
| 31 | ||
| 32 | visit(m: Modifiers.Modifier) is | |
| 33 | if isa Modifiers.INIT(m) \/ isa Modifiers.OPEN(m) then | |
| 34 | _locations.add(m.location); | |
| 35 | fi | |
| 36 | si | |
| 37 | ||
| 38 | // Primary-ctor parameter modifiers hang off the VARIABLE tree but | |
| 39 | // Variable.walk does not descend into them (that field is populated | |
| 40 | // only for primary-ctor params). Pump the list into the visitor | |
| 41 | // directly so `init` on a parameter registers. | |
| 42 | visit(v: Variables.VARIABLE) is | |
| 43 | if let v.modifiers? then | |
| 44 | modifiers.walk(self); | |
| 45 | fi | |
| 46 | si | |
| 47 | si | |
| 48 | si |