Ruby
2.0.0p247(2013-06-27revision41674)
|
00001 # -*- mode: ruby; coding: us-ascii -*- 00002 firstline, predefined = __LINE__+1, %[\ 00003 intern 00004 method_missing MethodMissing 00005 length 00006 size 00007 gets 00008 succ 00009 each 00010 proc 00011 lambda 00012 send 00013 __send__ 00014 initialize 00015 initialize_copy 00016 initialize_clone 00017 initialize_dup 00018 _ UScore 00019 "/*NULL*/" NULL 00020 empty? 00021 respond_to? Respond_to 00022 respond_to_missing? Respond_to_missing 00023 <IFUNC> 00024 <CFUNC> 00025 core#set_method_alias 00026 core#set_variable_alias 00027 core#undef_method 00028 core#define_method 00029 core#define_singleton_method 00030 core#set_postexe 00031 core#hash_from_ary 00032 core#hash_merge_ary 00033 core#hash_merge_ptr 00034 core#hash_merge_kwd 00035 ] 00036 00037 class KeywordError < RuntimeError 00038 def self.raise(mesg, line) 00039 super(self, mesg, ["#{__FILE__}:#{line}", *caller]) 00040 end 00041 end 00042 00043 predefined_ids = {} 00044 preserved_ids = [] 00045 local_ids = [] 00046 instance_ids = [] 00047 global_ids = [] 00048 const_ids = [] 00049 class_ids = [] 00050 names = {} 00051 predefined.split(/^/).each_with_index do |line, num| 00052 next if /^#/ =~ line 00053 line.sub!(/\s+#.*/, '') 00054 name, token = line.split 00055 next unless name 00056 token ||= name 00057 if /#/ =~ token 00058 token = "_#{token.gsub(/\W+/, '_')}" 00059 else 00060 token = token.sub(/\?/, 'P').sub(/\A[a-z]/) {$&.upcase} 00061 token.sub!(/\A\$/, "_G_") 00062 token.sub!(/\A@@/, "_C_") 00063 token.sub!(/\A@/, "_I_") 00064 token.gsub!(/\W+/, "") 00065 end 00066 if prev = names[name] 00067 KeywordError.raise("#{name} is already registered at line #{prev+firstline}", firstline+num) 00068 end 00069 if prev = predefined_ids[token] 00070 KeywordError.raise("#{token} is already used for #{prev} at line #{names[prev]+firstline}", firstline+num) 00071 end 00072 names[name] = num 00073 case name 00074 when /\A[A-Z]\w*\z/; const_ids 00075 when /\A(?!\d)\w+\z/; local_ids 00076 when /\A\$(?:\d+|(?!\d)\w+)\z/; global_ids 00077 when /\A@@(?!\d)\w+\z/; class_ids 00078 when /\A@(?!\d)\w+\z/; instance_ids 00079 when /\A((?!\d)\w+)=\z/ 00080 KeywordError.raise("use ID2ATTRSET(#{$1}) instead of ATTRSET #{name}", firstline+num) 00081 else preserved_ids 00082 end << token 00083 predefined_ids[token] = name 00084 end 00085 { 00086 "LOCAL" => local_ids, 00087 "INSTANCE" => instance_ids, 00088 "GLOBAL" => global_ids, 00089 "CONST" => const_ids, 00090 "CLASS" => class_ids, 00091 :preserved => preserved_ids, 00092 :predefined => predefined_ids, 00093 } 00094