Ruby  2.1.10p492(2016-04-01revision54464)
id.def
Go to the documentation of this file.
1 # -*- mode: ruby; coding: us-ascii -*-
2 firstline, predefined = __LINE__+1, %[\
3  freeze
4  inspect
5  intern
6  object_id
7  const_missing
8  method_missing MethodMissing
9  method_added
10  singleton_method_added
11  method_removed
12  singleton_method_removed
13  method_undefined
14  singleton_method_undefined
15  length
16  size
17  gets
18  succ
19  each
20  proc
21  lambda
22  send
23  __send__
24  __attached__
25  initialize
26  initialize_copy
27  initialize_clone
28  initialize_dup
29  _ UScore
30  "/*NULL*/" NULL
31  empty?
32  eql?
33  respond_to? Respond_to
34  respond_to_missing? Respond_to_missing
35  <IFUNC>
36  <CFUNC>
37  core#set_method_alias
38  core#set_variable_alias
39  core#undef_method
40  core#define_method
41  core#define_singleton_method
42  core#set_postexe
43  core#hash_from_ary
44  core#hash_merge_ary
45  core#hash_merge_ptr
46  core#hash_merge_kwd
47 ]
48 
49 class KeywordError < RuntimeError
50  def self.raise(mesg, line)
51  super(self, mesg, ["#{__FILE__}:#{line}", *caller])
52  end
53 end
54 
55 predefined_ids = {}
56 preserved_ids = []
57 local_ids = []
58 instance_ids = []
59 global_ids = []
60 const_ids = []
61 class_ids = []
62 names = {}
63 predefined.split(/^/).each_with_index do |line, num|
64  next if /^#/ =~ line
65  line.sub!(/\s+#.*/, '')
66  name, token = line.split
67  next unless name
68  token ||= name
69  if /#/ =~ token
70  token = "_#{token.gsub(/\W+/, '_')}"
71  else
72  token = token.sub(/\?/, 'P').sub(/\A[a-z]/) {$&.upcase}
73  token.sub!(/\A\$/, "_G_")
74  token.sub!(/\A@@/, "_C_")
75  token.sub!(/\A@/, "_I_")
76  token.gsub!(/\W+/, "")
77  end
78  if prev = names[name]
79  KeywordError.raise("#{name} is already registered at line #{prev+firstline}", firstline+num)
80  end
81  if prev = predefined_ids[token]
82  KeywordError.raise("#{token} is already used for #{prev} at line #{names[prev]+firstline}", firstline+num)
83  end
84  names[name] = num
85  case name
86  when /\A[A-Z]\w*\z/; const_ids
87  when /\A(?!\d)\w+\z/; local_ids
88  when /\A\$(?:\d+|(?!\d)\w+)\z/; global_ids
89  when /\A@@(?!\d)\w+\z/; class_ids
90  when /\A@(?!\d)\w+\z/; instance_ids
91  when /\A((?!\d)\w+)=\z/
92  KeywordError.raise("use ID2ATTRSET(#{$1}) instead of ATTRSET #{name}", firstline+num)
93  else preserved_ids
94  end << token
95  predefined_ids[token] = name
96 end
97 {
98  "LOCAL" => local_ids,
99  "INSTANCE" => instance_ids,
100  "GLOBAL" => global_ids,
101  "CONST" => const_ids,
102  "CLASS" => class_ids,
103  :preserved => preserved_ids,
104  :predefined => predefined_ids,
105 }