Class: Peruby::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/peruby/validator.rb

Overview

Compile-time lexical checks for the strict pragma.

Defined Under Namespace

Classes: State

Constant Summary collapse

SPECIAL =
%w[_ a b ARGV ENV INC SIG].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime = nil, strict = Set.new, warnings = Set.new) ⇒ Validator

Returns a new instance of Validator.



16
17
18
19
20
21
22
# File 'lib/peruby/validator.rb', line 16

def initialize(runtime = nil, strict = Set.new, warnings = Set.new)
  @runtime = runtime
  @strict = strict
  @warnings = warnings
  @package_uses = Hash.new { |uses, key| uses[key] = [] }
  @loop_labels = []
end

Class Method Details

.validate(node, runtime: nil, strict: Set.new, warnings: Set.new) ⇒ Object



12
13
14
# File 'lib/peruby/validator.rb', line 12

def self.validate(node, runtime: nil, strict: Set.new, warnings: Set.new)
  new(runtime, strict, warnings).validate(node)
end

Instance Method Details

#validate(node) ⇒ Object



24
25
26
27
28
# File 'lib/peruby/validator.rb', line 24

def validate(node)
  visit(node, State.new(@strict.dup, @warnings.dup, {}))
  warn_once
  node
end