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