引数にファイル名を入力して実行 ruby xxx.rb ....shader
text_name = ARGV[0] File.open(text_name) do |f| all_text = f.read#テキスト全体読み込み all_text.gsub!(/{\s*}/,"") p_text = all_text.match(/Properties\s*{(.*?)}/m)[0] puts "Debug Output Properties" puts p_text #xはフリーフォーマット表現、空白を無視する names = p_text.scan(/(_\w+?)\(/x) types = p_text.scan(/_\w+\(".+",(.+?)\)/x) names.flatten! types.flatten! i=0 puts "---------------Result----------------" while(i<names.size) do name = names[i] kind = types[i].sub(/\(.+/,"") typ = "" case kind when "Color" then typ = "fixed4" when "2D" then typ = "sampler2D" when "Vector" then typ = "float4" when "Range" then typ = "float" when "CUBE" then typ = "samplerCUBE" else typ = kind.downcase end puts "#{typ} #{name};" i+=1 end end