mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
id.def: check duplication
* defs/id.def (KeywordError): check duplication. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
298694a2fd
commit
2edcf87c1c
4 changed files with 18 additions and 3 deletions
|
@ -1,4 +1,6 @@
|
|||
Fri Dec 21 16:38:00 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Fri Dec 21 16:38:05 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* defs/id.def (KeywordError): check duplication.
|
||||
|
||||
* defs/id.def: support for other scope IDs,
|
||||
ID_{INSTANCE,GLOBAL,CONST,CLASS}.
|
||||
|
|
13
defs/id.def
13
defs/id.def
|
@ -33,6 +33,12 @@ firstline, predefined = __LINE__+1, %[\
|
|||
core#hash_merge_kwd
|
||||
]
|
||||
|
||||
class KeywordError < RuntimeError
|
||||
def self.raise(mesg, line)
|
||||
super(self, mesg, ["#{__FILE__}:#{line}", *caller])
|
||||
end
|
||||
end
|
||||
|
||||
predefined_ids = {}
|
||||
preserved_ids = []
|
||||
local_ids = []
|
||||
|
@ -53,6 +59,13 @@ predefined.lines.each_with_index do |line, num|
|
|||
token.sub!(/\A@/, "_I_")
|
||||
token.gsub!(/\W+/, "")
|
||||
end
|
||||
if prev = names[name]
|
||||
KeywordError.raise("#{name} is already registered at line #{prev+firstline}", firstline+num)
|
||||
end
|
||||
if prev = predefined_ids[token]
|
||||
KeywordError.raise("#{token} is already used for #{prev} at line #{names[prev]+firstline}", firstline+num)
|
||||
end
|
||||
names[name] = num
|
||||
case name
|
||||
when /\A[A-Z]\w*\z/; const_ids
|
||||
when /\A(?!\d)\w+\z/; local_ids
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
**********************************************************************/
|
||||
<%
|
||||
defs = File.join(File.dirname(erb.filename), "../defs/id.def")
|
||||
defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
|
||||
ids = eval(File.read(defs), binding, defs)
|
||||
%>
|
||||
static void
|
||||
|
|
|
@ -21,7 +21,7 @@ token_op_ids = %w[
|
|||
tCOLON2 tCOLON3
|
||||
]
|
||||
|
||||
defs = File.join(File.dirname(erb.filename), "../defs/id.def")
|
||||
defs = File.join(File.dirname(File.dirname(erb.filename)), "defs/id.def")
|
||||
ids = eval(File.read(defs), binding, defs)
|
||||
types = ids.keys.grep(/^[A-Z]/)
|
||||
%>
|
||||
|
|
Loading…
Reference in a new issue