class SheepAst::MatchFactory

Aggregated interface for the Matcher

The user syntax like E(:e, …) will be send to the gen method. The gen method calls Object's new method.

For the current supported Match kind and options please see links from the initialize method's [View source] pull down.

@see gen @see initialize

Public Class Methods

new() click to toggle source
Calls superclass method SheepAst::FactoryBase::new
# File lib/sheep_ast/match/match_factory.rb, line 36
def initialize
  @exact_match = ExactMatch.new
  @any_match = AnyMatch.new
  @regex_match = RegexMatch.new
  @exact_group_match = ExactGroupMatch.new
  @scoped_match = ScopedMatch.new
  @scoped_regex_match = ScopedRegexMatch.new
  @enclosed_match = EnclosedMatch.new
  @enclosed_regex_match = EnclosedRegexMatch.new
  @my_name = 'match_factory'
  super()
end

Public Instance Methods

gen(kind, *para, **options) click to toggle source
# File lib/sheep_ast/match/match_factory.rb, line 54
def gen(kind, *para, **options)
  ldebug? and ldebug "kind = #{kind.inspect}, para = #{para.inspect}, options = #{options.inspect}"

  match_arr = []
  repeat = options[:repeat].nil? ? 1..1 : 1..options[:repeat]

  repeat.each {
    match =
      case kind
      when :e    then @exact_match.new(*para, **options)
      when :r    then @regex_match.new(*para, **options)
      when :eg   then @exact_group_match.new(*para, **options)
      when :sc   then @scoped_match.new(*para, **options)
      when :scr  then @scoped_regex_match.new(*para, **options)
      when :enc  then @enclosed_match.new(*para, **options)
      when :encr then @enclosed_regex_match.new(*para, **options)
      when :any  then @any_match.new('any', *para, **options)
      when :eof  then @exact_match.new('__sheep_eof__', *para, **options)
      else
        application_error 'unknown match'
      end

    create_id(match)
    # match.data_store = @data_store
    match.kind_name_set(kind.to_s)
    match.node_tag = options[:node_tag]
    match.parent_tag = options[:parent_tag]
    match_arr << match
  }

  if match_arr.length == 1
    return T.cast(match_arr[0], MatchBase)
  else
    return match_arr
  end
end