module SheepAst::ConditionMatchUtil

Condition Match Util

Public Class Methods

new() click to toggle source
Calls superclass method SheepAst::Log::new
# File lib/sheep_ast/match/condition_match.rb, line 68
def initialize
  @condition_flag = false
  @pre_condition_flag = false
  @active_match = nil
  @condition_matches = {}
  @global_matches[MatchKind::Condition.rank] = @condition_matches
  @methods_array << prio(200, method(:check_condition_match))
  @regex_condition_matches = {}
  @global_matches[MatchKind::RegexCondition.rank] = @regex_condition_matches
  @methods_array << prio(210, method(:check_regex_condition_match))
  @methods_array << prio(10, method(:try_condition_scope))
  super()
end

Public Instance Methods

check_condition_match(data) click to toggle source
# File lib/sheep_ast/match/condition_match.rb, line 103
def check_condition_match(data)
  match = @condition_matches[data.expr]
  if !match.nil?
    ldebug? and ldebug "matched. expr = #{data.expr}. condition flag = true"
    @condition_flag = true
    @active_match = match
    @active_match.init
    @active_match.start_condition(data)
    @active_match.matched(data)
    return match
  end
  return nil
end
check_regex_condition_match(data) click to toggle source
# File lib/sheep_ast/match/condition_match.rb, line 120
def check_regex_condition_match(data)
  @regex_condition_matches.each do |_, match|
    test = match.match(data)
    next if test.nil?

    @condition_flag = true
    @active_match = match
    @active_match.init
    @active_match.start_condition(data)
    @active_match.matched(data)
    return match
  end
  return nil
end
condition_change?() click to toggle source
# File lib/sheep_ast/match/condition_match.rb, line 136
def condition_change?
  ldebug? and ldebug "condition_flag = #{@condition_flag}, pre_condition_flag = #{@pre_condition_flag}"
  if @condition_flag == @pre_condition_flag
    return false
  else
    ldebug? and ldebug 'condition change'
    @pre_condition_flag = @condition_flag
    return true
  end
end
try_condition_scope(data) click to toggle source
# File lib/sheep_ast/match/condition_match.rb, line 83
def try_condition_scope(data) # rubocop: disable all
  if @condition_flag
    if !@active_match.test_finish?(data)
      ldebug? and ldebug "In condition match. expr = #{data.expr}. condition flag = true. continue"
    else
      ldebug? and ldebug "matched. expr = #{data.expr}. condition flag = false"
      @condition_flag = false
      @active_match.end_condition(data)
      # @active_match.matched_end(data)
    end
    @active_match.matched(data)
  else
    @active_match = nil
  end
  return @active_match
end