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