1# -*- mode: ruby; coding: us-ascii -*-
2firstline, predefined = __LINE__+1, %[\
14 method_missing MethodMissing
16 singleton_method_added
18 singleton_method_removed
20 singleton_method_undefined
84 respond_to? Respond_to
85 respond_to_missing? Respond_to_missing
89 core#set_variable_alias
92 core#define_singleton_method
108# VM ID OP Parser Token
146class KeywordError < RuntimeError
147 def self.raise(mesg, line)
148 super(self, mesg, ["#{__FILE__}:#{line}", *caller])
152def id2varname(token, prefix = nil)
154 token = "_#{token.gsub(/\W+/, '_')}"
156 token = token.sub(/\?/, 'P')
157 token = prefix + token if prefix
158 token.sub!(/\A[a-z]/) {$&.upcase}
159 token.sub!(/\A\$/, "_G_")
160 token.sub!(/\A@@/, "_C_")
161 token.sub!(/\A@/, "_I_")
162 token.gsub!(/\W+/, "")
177predefined.split(/^/).each_with_index do |line, num|
179 line.sub!(/\s+#.*/, '')
180 name, token = line.split
182 token = id2varname(token || name)
184 preserved_ids << token
187 if prev = names[name]
188 KeywordError.raise("#{name} is already registered at line #{prev+firstline}", firstline+num)
190 if prev = predefined_ids[token]
191 KeywordError.raise("#{token} is already used for #{prev} at line #{names[prev]+firstline}", firstline+num)
195 when /\A[A-Z]\w*\z/; const_ids
196 when /\A(?!\d)\w+\z/; local_ids
197 when /\A\$(?:\d+|(?!\d)\w+|\W)\z/; global_ids
198 when /\A@@(?!\d)\w+\z/; class_ids
199 when /\A@(?!\d)\w+\z/; instance_ids
200 when /\A((?!\d)\w+)=\z/; attrset_ids
203 predefined_ids[token] = name
206token_ops.split(/^/).each do |line|
208 line.sub!(/\s+#.*/, '')
209 id, op, token = line.split
210 next unless id and op
211 token ||= (id unless /\A\W\z/ =~ op)
212 token_op_ids << [id, op, token, (index += 1 if token)]
215 "LOCAL" => local_ids,
216 "INSTANCE" => instance_ids,
217 "GLOBAL" => global_ids,
218 "CONST" => const_ids,
219 "CLASS" => class_ids,
220 "ATTRSET" => attrset_ids,
221 :preserved => preserved_ids,
222 :predefined => predefined_ids,
223 :token_op => token_op_ids,
224 :last_token => index,