Ruby  2.5.0dev(2017-10-22revision60238)
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  inspect
7  intern
8  object_id
9  const_missing
10  method_missing MethodMissing
11  method_added
12  singleton_method_added
13  method_removed
14  singleton_method_removed
15  method_undefined
16  singleton_method_undefined
17  length
18  size
19  gets
20  succ
21  each
22  proc
23  lambda
24  send
25  __send__
26  __attached__
27  initialize
28  initialize_copy
29  initialize_clone
30  initialize_dup
31  to_int
32  to_ary
33  to_str
34  to_sym
35  to_hash
36  to_proc
37  to_io
38  to_a
39  to_s
40  to_i
41  to_r
42  bt
43  bt_locations
44  call
45  mesg
46  exception
47  not NOT
48  and AND
49  or OR
50 
51  _ UScore
52  "/*NULL*/" NULL
53  empty?
54  eql?
55  respond_to? Respond_to
56  respond_to_missing? Respond_to_missing
57  <IFUNC>
58  <CFUNC>
59  core#set_method_alias
60  core#set_variable_alias
61  core#undef_method
62  core#define_method
63  core#define_singleton_method
64  core#set_postexe
65  core#hash_from_ary
66  core#hash_merge_ary
67  core#hash_merge_ptr
68  core#hash_merge_kwd
69 
70  - debug#created_info
71 
72  $_ LASTLINE
73  $~ BACKREF
74 ]
75 
76 # VM ID OP Parser Token
77 token_ops = %[\
78  Dot2 .. DOT2
79  Dot3 ... DOT3
80  UPlus +@ UPLUS
81  UMinus -@ UMINUS
82  Pow ** POW
83  Cmp <=> CMP
84  PLUS +
85  MINUS -
86  MULT *
87  DIV /
88  MOD %
89  LTLT << LSHFT
90  GTGT >> RSHFT
91  LT <
92  LE <= LEQ
93  GT >
94  GE >= GEQ
95  Eq == EQ
96  Eqq === EQQ
97  Neq != NEQ
98  Not !
99  Backquote `
100  EqTilde =~ MATCH
101  NeqTilde !~ NMATCH
102  AREF []
103  ASET []=
104  COLON2 ::
105  ANDOP &&
106  OROP ||
107  ANDDOT &.
108 ]
109 
110 class KeywordError < RuntimeError
111  def self.raise(mesg, line)
112  super(self, mesg, ["#{__FILE__}:#{line}", *caller])
113  end
114 end
115 
116 predefined_ids = {}
117 preserved_ids = []
118 local_ids = []
119 instance_ids = []
120 global_ids = []
121 const_ids = []
122 class_ids = []
123 attrset_ids = []
124 token_op_ids = []
125 names = {}
126 predefined.split(/^/).each_with_index do |line, num|
127  next if /^#/ =~ line
128  line.sub!(/\s+#.*/, '')
129  name, token = line.split
130  next unless name
131  token ||= name
132  if /#/ =~ token
133  token = "_#{token.gsub(/\W+/, '_')}"
134  else
135  token = token.sub(/\?/, 'P').sub(/\A[a-z]/) {$&.upcase}
136  token.sub!(/\A\$/, "_G_")
137  token.sub!(/\A@@/, "_C_")
138  token.sub!(/\A@/, "_I_")
139  token.gsub!(/\W+/, "")
140  end
141  if name == '-'
142  preserved_ids << token
143  next
144  end
145  if prev = names[name]
146  KeywordError.raise("#{name} is already registered at line #{prev+firstline}", firstline+num)
147  end
148  if prev = predefined_ids[token]
149  KeywordError.raise("#{token} is already used for #{prev} at line #{names[prev]+firstline}", firstline+num)
150  end
151  names[name] = num
152  case name
153  when /\A[A-Z]\w*\z/; const_ids
154  when /\A(?!\d)\w+\z/; local_ids
155  when /\A\$(?:\d+|(?!\d)\w+|\W)\z/; global_ids
156  when /\A@@(?!\d)\w+\z/; class_ids
157  when /\A@(?!\d)\w+\z/; instance_ids
158  when /\A((?!\d)\w+)=\z/; attrset_ids
159  else preserved_ids
160  end << token
161  predefined_ids[token] = name
162 end
163 token_ops.split(/^/).each do |line|
164  next if /^#/ =~ line
165  line.sub!(/\s+#.*/, '')
166  id, op, token = line.split
167  next unless id and op
168  token ||= (id unless /\A\W\z/ =~ op)
169  token_op_ids << [id, op, token]
170 end
171 {
172  "LOCAL" => local_ids,
173  "INSTANCE" => instance_ids,
174  "GLOBAL" => global_ids,
175  "CONST" => const_ids,
176  "CLASS" => class_ids,
177  "ATTRSET" => attrset_ids,
178  :preserved => preserved_ids,
179  :predefined => predefined_ids,
180  :token_op => token_op_ids,
181 }