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