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