Class: Ibex::Normalize::PhaseGuard

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/normalize/phase_guard.rb

Overview

Verifies the ordered boundaries of normalization phases.

Constant Summary collapse

PHASES =
%i[
  declarations parameter_templates inline_rules symbols parser_contract
  productions expansions validation build
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePhaseGuard

Returns a new instance of PhaseGuard.



19
20
21
22
23
# File 'lib/ibex/normalize/phase_guard.rb', line 19

def initialize
  @phase = :initialized
  @index = 0 #: Integer
  @active = false #: bool
end

Instance Attribute Details

#phaseObject (readonly)

: Symbol



13
14
15
# File 'lib/ibex/normalize/phase_guard.rb', line 13

def phase
  @phase
end

Instance Method Details

#begin_phase!(phase) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/ibex/normalize/phase_guard.rb', line 26

def begin_phase!(phase)
  raise "normalization is already complete" if @index == PHASES.length
  raise "normalization phase already active: #{@phase}" if @active

  expected = PHASES.fetch(@index)
  raise "normalization phase order drift: expected #{expected}, got #{phase}" unless phase == expected

  @phase = phase
  @active = true
end

#complete_phase!Object



38
39
40
41
42
43
44
# File 'lib/ibex/normalize/phase_guard.rb', line 38

def complete_phase!
  raise "normalization phase completion without an active phase" unless @active

  @index += 1
  @active = false
  @phase = :complete if @index == PHASES.length
end