Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

id.def
Go to the documentation of this file.
1 # -*- mode: ruby; coding: us-ascii -*-
2 firstline, predefined = __LINE__+1, %[\
3 max
4 min
5 freeze
6 nil?
7 inspect
8 intern
9 object_id
10 const_missing
11 method_missing MethodMissing
12 method_added
13 singleton_method_added
14 method_removed
15 singleton_method_removed
16 method_undefined
17 singleton_method_undefined
18 length
19 size
20 gets
21 succ
22 each
23 proc
24 lambda
25 send
26 __send__
27 __attached__
28 initialize
29 initialize_copy
30 initialize_clone
31 initialize_dup
32 to_int
33 to_ary
34 to_str
35 to_sym
36 to_hash
37 to_proc
38 to_io
39 to_a
40 to_s
41 to_i
42 to_f
43 to_r
44 bt
45 bt_locations
46 call
47 mesg
48 exception
49 locals
50 not NOT
51 and AND
52 or OR
53 div
54 divmod
55 fdiv
56 quo
57 name
58 nil
59
60 _ UScore
61
62 # MUST be successive
63 _1 NUMPARAM_1
64 _2 NUMPARAM_2
65 _3 NUMPARAM_3
66 _4 NUMPARAM_4
67 _5 NUMPARAM_5
68 _6 NUMPARAM_6
69 _7 NUMPARAM_7
70 _8 NUMPARAM_8
71 _9 NUMPARAM_9
72
73 "/*NULL*/" NULL
74 empty?
75 eql?
76 respond_to? Respond_to
77 respond_to_missing? Respond_to_missing
78 <IFUNC>
79 <CFUNC>
80 core#set_method_alias
81 core#set_variable_alias
82 core#undef_method
83 core#define_method
84 core#define_singleton_method
85 core#set_postexe
86 core#hash_merge_ptr
87 core#hash_merge_kwd
88 core#raise
89
90 - debug#created_info
91
92 $_ LASTLINE
93 $~ BACKREF
94 $! ERROR_INFO
95 ]
96
97 # VM ID OP Parser Token
98 token_ops = %[\
99 Dot2 .. DOT2
100 Dot3 ... DOT3
101 BDot2 .. BDOT2
102 BDot3 ... BDOT3
103 UPlus +@ UPLUS
104 UMinus -@ UMINUS
105 Pow ** POW
106 Cmp <=> CMP
107 PLUS +
108 MINUS -
109 MULT *
110 DIV /
111 MOD %
112 LTLT << LSHFT
113 GTGT >> RSHFT
114 LT <
115 LE <= LEQ
116 GT >
117 GE >= GEQ
118 Eq == EQ
119 Eqq === EQQ
120 Neq != NEQ
121 Not !
122 And &
123 Or |
124 Backquote `
125 EqTilde =~ MATCH
126 NeqTilde !~ NMATCH
127 AREF []
128 ASET []=
129 COLON2 ::
130 ANDOP &&
131 OROP ||
132 ANDDOT &.
133 ]
134
135 class KeywordError < RuntimeError
136 def self.raise(mesg, line)
137 super(self, mesg, ["#{__FILE__}:#{line}", *caller])
138 end
139 end
140
141 predefined_ids = {}
142 preserved_ids = []
143 local_ids = []
144 instance_ids = []
145 global_ids = []
146 const_ids = []
147 class_ids = []
148 attrset_ids = []
149 token_op_ids = []
150 names = {}
151 predefined.split(/^/).each_with_index do |line, num|
152 next if /^#/ =~ line
153 line.sub!(/\s+#.*/, '')
154 name, token = line.split
155 next unless name
156 token ||= name
157 if /#/ =~ token
158 token = "_#{token.gsub(/\W+/, '_')}"
159 else
160 token = token.sub(/\?/, 'P').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 if name == '-'
167 preserved_ids << token
168 next
169 end
170 if prev = names[name]
171 KeywordError.raise("#{name} is already registered at line #{prev+firstline}", firstline+num)
172 end
173 if prev = predefined_ids[token]
174 KeywordError.raise("#{token} is already used for #{prev} at line #{names[prev]+firstline}", firstline+num)
175 end
176 names[name] = num
177 case name
178 when /\A[A-Z]\w*\z/; const_ids
179 when /\A(?!\d)\w+\z/; local_ids
180 when /\A\$(?:\d+|(?!\d)\w+|\W)\z/; global_ids
181 when /\A@@(?!\d)\w+\z/; class_ids
182 when /\A@(?!\d)\w+\z/; instance_ids
183 when /\A((?!\d)\w+)=\z/; attrset_ids
184 else preserved_ids
185 end << token
186 predefined_ids[token] = name
187 end
188 token_ops.split(/^/).each do |line|
189 next if /^#/ =~ line
190 line.sub!(/\s+#.*/, '')
191 id, op, token = line.split
192 next unless id and op
193 token ||= (id unless /\A\W\z/ =~ op)
194 token_op_ids << [id, op, token]
195 end
196 {
197 "LOCAL" => local_ids,
198 "INSTANCE" => instance_ids,
199 "GLOBAL" => global_ids,
200 "CONST" => const_ids,
201 "CLASS" => class_ids,
202 "ATTRSET" => attrset_ids,
203 :preserved => preserved_ids,
204 :predefined => predefined_ids,
205 :token_op => token_op_ids,
206 }