lib/rio/matchrecord.rb in rio-0.5.1 vs lib/rio/matchrecord.rb in rio-0.6.0

- old
+ new

@@ -1,8 +1,8 @@ #-- # =========================================================================== -# Copyright (c) 2005-2012 Christopher Kleckner +# Copyright (c) 2005-2017 Christopher Kleckner # All rights reserved # # This file is part of the Rio library for ruby. # # Rio is free software; you can redistribute it and/or modify @@ -53,34 +53,30 @@ @select_arg.match(val) end end class Range < Base def match?(val,recno) - #p "match?(#{val},#{recno}) select_arg=#{@select_arg}" @select_arg === recno end end - class Fixnum < Base + class Integer < Base def match?(val,recno) - #p "match?(#{val},#{recno}) select_arg=#{@select_arg}" @select_arg === recno end end class Proc < Base def initialize(arg,therio) super(arg) @therio = therio end def match?(val,recno) - #p "match?(#{val},#{recno}) select_arg=#{@select_arg}" args = [val,recno,@therio] @select_arg.call(*args[0,@select_arg.arity]) end end class Symbol < Base def match?(val,recno) - #p "match?(#{val},#{recno}) select_arg=#{@select_arg}" val.__send__(@select_arg) end end class And < Base def initialize(matches,therio) @@ -90,17 +86,15 @@ end super(list) @therio = therio end def match?(val,recno) - #p "match?(#{val},#{recno}) select_arg=#{@select_arg}" @select_arg.all? { |sel| sel.match?(val,recno) } end end class Case < Base def match?(val,recno) - #p "match?(#{val},#{recno}) select_arg=#{@select_arg}" @select_arg === val end end def create(therio,arg) case arg @@ -110,12 +104,12 @@ Match::Record::Range.new(arg) when ::Proc Match::Record::Proc.new(arg,therio) when ::Symbol Match::Record::Symbol.new(arg) - when ::Fixnum - Match::Record::Fixnum.new(arg) + when ::Integer + Match::Record::Integer.new(arg) when ::Array Match::Record::And.new(arg,therio) else Match::Record::Case.new(arg) end @@ -139,18 +133,17 @@ @list = [] args.each do |arg| @list << create_sel(therio,arg) end end - #p "SelList(#{args.inspect},#{@list.inspect})" end def inspect @list.inspect end def size() @list.size unless @list.nil? end def only_one_fixnum?() - @list && @list.size == 1 && @list[0].kind_of?(Match::Record::Fixnum) + @list && @list.size == 1 && @list[0].kind_of?(Match::Record::Integer) end def delete_at(index) @list.delete_at(index) @list = nil if @list.empty? end @@ -170,37 +163,18 @@ @list = (newlist.empty? ? nil : newlist) if newlist.length != @list.length @list.nil? ? nil : self end def create_sel(therio,arg) Match::Record.create(therio,arg) -# case arg -# when ::Regexp -# Match::Record::RegExp.new(arg) -# when ::Range -# Match::Record::Range.new(arg) -# when ::Proc -# Match::Record::Proc.new(arg,therio) -# when ::Symbol -# Match::Record::Symbol.new(arg) -# when ::Fixnum -# Match::Record::Fixnum.new(arg) -# when ::Array -# Match::Record::And.new(arg) -# else -# raise ArgumentError,"Argument must be a Regexp,Range,Fixnum,Proc, or Symbol" -# end end def match?(val,recno) - # !@list.nil? && (@list.empty? || @list.detect { |sel| sel.match?(val,recno) } || false) && true return false unless @list return true if @list.empty? as = nil al = @list.detect { |sel| as = sel.match?(val,recno) - #p "1: #{$1} as[match?]: #{as.inspect}" as } - #p "[SelList.match?] as:#{as.inspect} al:#{al.inspect}" return as if al return false end def always?() !@list.nil? && @list.empty? end def never?() @list.nil? end @@ -254,14 +228,11 @@ end def never?() @always == false end def match?(val,recno) - #p "match?(#{val},#{recno}) #{self.inspect}" return @always if @always - #return @always unless @always.nil? as = nil - #ok = ((!@sel.nil? && (as = @sel.match?(val,recno))) && !(!@rej.nil? && @rej.match?(val,recno))) ok = ((@sel && (as = @sel.match?(val,recno))) && !(@rej && @rej.match?(val,recno))) return (ok ? as : ok) end end end