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