Ruby 4.1.0dev (2026-10-12 revision 9e8bf7356b920f9c26517ea0197551195bc32430)
id.def
1# -*- mode: ruby; coding: us-ascii -*-
2firstline, predefined = __LINE__+1, %[\
3 max
4 min
5 hash
6 freeze
7 nil?
8 inspect
9 intern
10 object_id
11 __id__
12 const_added
13 const_missing
14 method_missing MethodMissing
15 method_added
16 singleton_method_added
17 method_removed
18 singleton_method_removed
19 method_undefined
20 singleton_method_undefined
21 length
22 size
23 gets
24 succ
25 each
26 proc
27 lambda
28 send
29 __send__
30 __recursive_key__
31 clone
32 initialize
33 initialize_copy
34 initialize_clone
35 initialize_dup
36 to_int
37 to_ary
38 to_str
39 to_sym
40 to_hash
41 to_proc
42 to_io
43 to_a
44 to_s
45 to_i
46 to_f
47 to_r
48 bt
49 bt_locations
50 call
51 yield
52 mesg
53 exception
54 locals
55 not NOT
56 and AND
57 or OR
58 div
59 divmod
60 fdiv
61 quo
62 name
63 nil
64 path
65 pack
66 buffer
67 include?
68 aborted
69 exited
70
71 _ UScore
72
73 # MUST be successive
74 _1 NUMPARAM_1
75 _2 NUMPARAM_2
76 _3 NUMPARAM_3
77 _4 NUMPARAM_4
78 _5 NUMPARAM_5
79 _6 NUMPARAM_6
80 _7 NUMPARAM_7
81 _8 NUMPARAM_8
82 _9 NUMPARAM_9
83 <it> ItImplicit
84 it It
85
86 "/*NULL*/" NULL
87 empty?
88 eql?
89 default
90 respond_to? Respond_to
91 respond_to_missing? Respond_to_missing
92 <IFUNC>
93 <CFUNC>
94 core#set_method_alias
95 core#set_variable_alias
96 core#undef_method
97 core#define_method
98 core#define_singleton_method
99 core#iseq_path
100 core#set_postexe
101 core#hash_merge_ptr
102 core#hash_merge_bang_ptr
103 core#hash_merge_kwd
104 core#hash_merge_bang_kwd
105 core#hash_coerce
106 core#raise
107 core#sprintf
108
109 - debug#created_info
110
111 $_ LASTLINE
112 $~ BACKREF
113 $! ERROR_INFO
114
115 Ruby
116]
117
118# VM ID OP Parser Token
119token_ops = %[\
120 Dot2 .. DOT2
121 Dot3 ... DOT3
122 BDot2 .. BDOT2
123 BDot3 ... BDOT3
124 UPlus +@ UPLUS
125 UMinus -@ UMINUS
126 Pow ** POW
127 Cmp <=> CMP
128 PLUS +
129 MINUS -
130 MULT *
131 DIV /
132 MOD %
133 LTLT << LSHFT
134 GTGT >> RSHFT
135 LT <
136 LE <= LEQ
137 GT >
138 GE >= GEQ
139 Eq == EQ
140 Eqq === EQQ
141 Neq != NEQ
142 Not !
143 And &
144 Or |
145 Backquote `
146 EqTilde =~ MATCH
147 NeqTilde !~ NMATCH
148 AREF []
149 ASET []=
150 COLON2 ::
151 ANDOP &&
152 OROP ||
153 ANDDOT &.
154]
155
156class KeywordError < RuntimeError
157 def self.raise(mesg, line)
158 super(self, mesg, ["#{__FILE__}:#{line}", *caller])
159 end
160end
161
162def id2varname(token, prefix = nil)
163 if /#/ =~ token
164 token = "_#{token.gsub(/\W+/, '_')}"
165 else
166 token = token.sub(/\?/, 'P')
167 token = prefix + token if prefix
168 token.sub!(/\A[a-z]/) {$&.upcase}
169 token.sub!(/\A\$/, "_G_")
170 token.sub!(/\A@@/, "_C_")
171 token.sub!(/\A@/, "_I_")
172 token.gsub!(/\W+/, "")
173 end
174 token
175end
176
177predefined_ids = {}
178preserved_ids = []
179local_ids = []
180instance_ids = []
181global_ids = []
182const_ids = []
183class_ids = []
184attrset_ids = []
185token_op_ids = []
186names = {}
187predefined.split(/^/).each_with_index do |line, num|
188 next if /^#/ =~ line
189 line.sub!(/\s+#.*/, '')
190 name, token = line.split
191 next unless name
192 token = id2varname(token || name)
193 if name == '-'
194 preserved_ids << token
195 next
196 end
197 if prev = names[name]
198 KeywordError.raise("#{name} is already registered at line #{prev+firstline}", firstline+num)
199 end
200 if prev = predefined_ids[token]
201 KeywordError.raise("#{token} is already used for #{prev} at line #{names[prev]+firstline}", firstline+num)
202 end
203 names[name] = num
204 case name
205 when /\A[A-Z]\w*\z/; const_ids
206 when /\A(?!\d)\w+\z/; local_ids
207 when /\A\$(?:\d+|(?!\d)\w+|\W)\z/; global_ids
208 when /\A@@(?!\d)\w+\z/; class_ids
209 when /\A@(?!\d)\w+\z/; instance_ids
210 when /\A((?!\d)\w+)=\z/; attrset_ids
211 else preserved_ids
212 end << token
213 predefined_ids[token] = name
214end
215index = 127
216token_ops.split(/^/).each do |line|
217 next if /^#/ =~ line
218 line.sub!(/\s+#.*/, '')
219 id, op, token = line.split
220 next unless id and op
221 token ||= (id unless /\A\W\z/ =~ op)
222 token_op_ids << [id, op, token, (index += 1 if token)]
223end
224{
225 "LOCAL" => local_ids,
226 "INSTANCE" => instance_ids,
227 "GLOBAL" => global_ids,
228 "CONST" => const_ids,
229 "CLASS" => class_ids,
230 "ATTRSET" => attrset_ids,
231 :preserved => preserved_ids,
232 :predefined => predefined_ids,
233 :token_op => token_op_ids,
234 :last_token => index,
235}