Class ScopeVariableCollector

java.lang.Object
org.ek9lang.compiler.phase5.ScopeVariableCollector

final class ScopeVariableCollector extends Object
Walks a callable's parse tree to collect the variable symbols accessible within it - the local variables declared in its (possibly nested) instruction blocks, and the property fields of its enclosing aggregate. The caller supplies a Predicate so each name-quality check can apply its own admission rule (e.g. a permissive 'is a variable' filter, or a restrictive one that also excludes returning parameters, property fields and loop variables).

This centralises the ~150-line grammar-shape navigation that was previously copy-pasted across the three name-quality checks (confusingly-similar, non-descriptive and operator-keyword names), where any grammar change had to be applied in triplicate.

  • Constructor Details

    • ScopeVariableCollector

      ScopeVariableCollector(SymbolsAndScopes symbolsAndScopes)
  • Method Details

    • collectLocalVariables

      List<ISymbol> collectLocalVariables(org.antlr.v4.runtime.tree.ParseTree node, Predicate<ISymbol> filter)
      Collect the local variable symbols declared inside the callable's instruction blocks (including those nested in if/while/for/try/switch), admitting only those for which the filter holds.
    • getAccessibleFields

      List<ISymbol> getAccessibleFields(IScope scope)
      The property fields of the nearest enclosing aggregate, or an empty list if there is none.
    • namedCaptures

      List<ISymbol> namedCaptures(org.antlr.v4.runtime.tree.ParseTree node)
      THE variables a NAMED capture '(name: value)' introduces on a dynamic function or class - read by every name-quality check (E11030, E11031, E11032; C-1: only E11031 once collected them, FE57). They are variables like any other, so they obey the same naming rules. An unnamed capture reuses a name already checked where it was declared, so it is skipped rather than reported twice. The capture scope defines its symbols in expression order, so pairing with the params is positional. Empty for any other node.