Ruby 4.1.0dev (2026-09-07 revision b57404b461ba8bf34e802d86b0db78388216e182)
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#set_postexe
100 core#hash_merge_ptr
101 core#hash_merge_bang_ptr
102 core#hash_merge_kwd
103 core#hash_merge_bang_kwd
104 core#hash_coerce
105 core#raise
106 core#sprintf
107
108 - debug#created_info
109
110 $_ LASTLINE
111 $~ BACKREF
112 $! ERROR_INFO
113
114 Ruby
115]
116
117# VM ID OP Parser Token
118token_ops = %[\
119 Dot2 .. DOT2
120 Dot3 ... DOT3
121 BDot2 .. BDOT2
122 BDot3 ... BDOT3
123 UPlus +@ UPLUS
124 UMinus -@ UMINUS
125 Pow ** POW
126 Cmp <=> CMP
127 PLUS +
128 MINUS -
129 MULT *
130 DIV /
131 MOD %
132 LTLT << LSHFT
133 GTGT >> RSHFT
134 LT <
135 LE <= LEQ
136 GT >
137 GE >= GEQ
138 Eq == EQ
139 Eqq === EQQ
140 Neq != NEQ
141 Not !
142 And &
143 Or |
144 Backquote `
145 EqTilde =~ MATCH
146 NeqTilde !~ NMATCH
147 AREF []
148 ASET []=
149 COLON2 ::
150 ANDOP &&
151 OROP ||
152 ANDDOT &.
153]
154
155class KeywordError < RuntimeError
156 def self.raise(mesg, line)
157 super(self, mesg, ["#{__FILE__}:#{line}", *caller])
158 end
159end
160
161def id2varname(token, prefix = nil)
162 if /#/ =~ token
163 token = "_#{token.gsub(/\W+/, '_')}"
164 else
165 token = token.sub(/\?/, 'P')
166 token = prefix + token if prefix
167 token.sub!(/\A[a-z]/) {$&.upcase}
168 token.sub!(/\A\$/, "_G_")
169 token.sub!(/\A@@/, "_C_")
170 token.sub!(/\A@/, "_I_")
171 token.gsub!(/\W+/, "")
172 end
173 token
174end
175
176predefined_ids = {}
177preserved_ids = []
178local_ids = []
179instance_ids = []
180global_ids = []
181const_ids = []
182class_ids = []
183attrset_ids = []
184token_op_ids = []
185names = {}
186predefined.split(/^/).each_with_index do |line, num|
187 next if /^#/ =~ line
188 line.sub!(/\s+#.*/, '')
189 name, token = line.split
190 next unless name
191 token = id2varname(token || name)
192 if name == '-'
193 preserved_ids << token
194 next
195 end
196 if prev = names[name]
197 KeywordError.raise("#{name} is already registered at line #{prev+firstline}", firstline+num)
198 end
199 if prev = predefined_ids[token]
200 KeywordError.raise("#{token} is already used for #{prev} at line #{names[prev]+firstline}", firstline+num)
201 end
202 names[name] = num
203 case name
204 when /\A[A-Z]\w*\z/; const_ids
205 when /\A(?!\d)\w+\z/; local_ids
206 when /\A\$(?:\d+|(?!\d)\w+|\W)\z/; global_ids
207 when /\A@@(?!\d)\w+\z/; class_ids
208 when /\A@(?!\d)\w+\z/; instance_ids
209 when /\A((?!\d)\w+)=\z/; attrset_ids
210 else preserved_ids
211 end << token
212 predefined_ids[token] = name
213end
214index = 127
215token_ops.split(/^/).each do |line|
216 next if /^#/ =~ line
217 line.sub!(/\s+#.*/, '')
218 id, op, token = line.split
219 next unless id and op
220 token ||= (id unless /\A\W\z/ =~ op)
221 token_op_ids << [id, op, token, (index += 1 if token)]
222end
223{
224 "LOCAL" => local_ids,
225 "INSTANCE" => instance_ids,
226 "GLOBAL" => global_ids,
227 "CONST" => const_ids,
228 "CLASS" => class_ids,
229 "ATTRSET" => attrset_ids,
230 :preserved => preserved_ids,
231 :predefined => predefined_ids,
232 :token_op => token_op_ids,
233 :last_token => index,
234}