Class: Collie::Linter::Rules::UndefinedSymbol

Inherits:
Base
  • Object
show all
Defined in:
lib/collie/linter/rules/undefined_symbol.rb

Overview

Detects references to undeclared tokens or nonterminals

Constant Summary

Constants inherited from Base

Base::VALID_SEVERITIES

Instance Method Summary collapse

Methods inherited from Base

#autocorrectable?, #initialize

Constructor Details

This class inherits a constructor from Collie::Linter::Base

Instance Method Details

#check(ast, context = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/collie/linter/rules/undefined_symbol.rb', line 15

def check(ast, context = {})
  symbol_table = context[:symbol_table] || build_symbol_table(ast)

  each_rule_like(ast) do |rule|
    allowed_symbols = rule_like_parameters(rule)
    rule.alternatives.each do |alt|
      alt.symbols.each { |symbol| check_symbol(symbol_table, symbol, allowed_symbols: allowed_symbols) }
    end
  end

  check_declarations(ast, symbol_table)

  @offenses
end