class SheepAst::Let

Let action instance

@example

A(:let, [funcion1, *para, **option], [function2, *para, **options]] ...

This let data to handle given functions. pre made API is included like LetRedirect module

Attributes

fsyms[RW]

Public Class Methods

within(&blk) click to toggle source
# File lib/sheep_ast/action/let.rb, line 119
def self.within(&blk)
  class_eval(&blk)
end

Public Instance Methods

action(data, node) click to toggle source
# File lib/sheep_ast/action/let.rb, line 65
def action(data, node)
  @data = data
  @node = node
  @ret = MatchAction::Finish

  key_data = keyword_data(data)
  ldebug? and ldebug "let handle data #{key_data.inspect} to : "
  fsyms.each do |fsym|
    ret = nil
    m = fsym[0]
    para = []
    opt = {}
    if fsym.length > 1
      opt = fsym[-1]
      para = fsym[1..-2]
      if !opt.is_a?(Hash)
        para << opt
        opt = {}
      end
    end
    ldebug? and ldebug "Function : #{m}, para = #{para.inspect}"
    if para.nil? || para.empty?
      ret = T.unsafe(self).method(m).call(key_data, @data_store, **opt)
    else
      ret = T.unsafe(self).method(m).call(key_data, @data_store, *para, **opt)
    end

    if ret == true # rubocop:disable all
      if @_pwarn.nil?
        @_pwarn = true
        lwarn "Registered method = [#{method(m).name}] returned true."\
          'Follows methods are ignored.', :red
        lwarn 'Exited method loop. This message is printed only once per let object.', :red
      end
      break
    end
  end
  ldebug? and ldebug "let end. returns result = #{@ret}"

  return @ret
end
ctime_get() click to toggle source
# File lib/sheep_ast/action/let.rb, line 124
def ctime_get
  @action_factory.ctime
end
description() click to toggle source
# File lib/sheep_ast/action/let.rb, line 108
def description
  str = "#{name}: "
  fsyms.each do |fsym|
    m = fsym[0]

    para = fsym[1..-1] #rubocop: disable all
    str += "Function : #{m}, para = #{para.inspect}, "
  end
  return str.chomp.chomp
end
get_first_match(data) click to toggle source
# File lib/sheep_ast/action/let.rb, line 129
def get_first_match(data)
  id_ = data.stack.first
  match = T.cast(match_factory.from_id(id_), MatchBase)

  return match
end
get_last_match(data) click to toggle source
# File lib/sheep_ast/action/let.rb, line 137
def get_last_match(data)
  id_ = data.stack.last
  match = T.cast(match_factory.from_id(id_), MatchBase)

  return match
end
get_match(data, key) click to toggle source
# File lib/sheep_ast/action/let.rb, line 145
def get_match(data, key)
  test = data.stack_symbol.find_index { |i| i == key }

  id_ = data.stack[T.must(test)]
  match = T.cast(match_factory.from_id(id_), MatchBase)

  return match
end
new(*fsyms, **options) click to toggle source
# File lib/sheep_ast/action/let.rb, line 57
def new(*fsyms, **options)
  ins = Let.new
  ins.fsyms = fsyms
  return ins
end