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