2012-12-21 02:38:03 -05:00
|
|
|
# -*- mode: ruby; coding: us-ascii -*-
|
|
|
|
firstline, predefined = __LINE__+1, %[\
|
2016-03-17 08:47:31 -04:00
|
|
|
max
|
|
|
|
min
|
2013-11-09 16:17:06 -05:00
|
|
|
freeze
|
2019-08-02 10:25:38 -04:00
|
|
|
nil?
|
2013-05-02 03:54:17 -04:00
|
|
|
inspect
|
2012-12-04 12:36:19 -05:00
|
|
|
intern
|
2013-05-02 03:54:17 -04:00
|
|
|
object_id
|
|
|
|
const_missing
|
2012-12-04 12:36:19 -05:00
|
|
|
method_missing MethodMissing
|
2013-05-02 03:54:17 -04:00
|
|
|
method_added
|
|
|
|
singleton_method_added
|
|
|
|
method_removed
|
|
|
|
singleton_method_removed
|
|
|
|
method_undefined
|
|
|
|
singleton_method_undefined
|
2012-12-04 12:36:19 -05:00
|
|
|
length
|
|
|
|
size
|
|
|
|
gets
|
|
|
|
succ
|
|
|
|
each
|
2013-04-30 22:38:44 -04:00
|
|
|
proc
|
2012-12-04 12:36:19 -05:00
|
|
|
lambda
|
|
|
|
send
|
|
|
|
__send__
|
2013-05-02 03:54:17 -04:00
|
|
|
__attached__
|
2012-12-04 12:36:19 -05:00
|
|
|
initialize
|
|
|
|
initialize_copy
|
|
|
|
initialize_clone
|
|
|
|
initialize_dup
|
2014-05-20 02:28:52 -04:00
|
|
|
to_int
|
|
|
|
to_ary
|
|
|
|
to_str
|
|
|
|
to_sym
|
|
|
|
to_hash
|
|
|
|
to_proc
|
|
|
|
to_io
|
|
|
|
to_a
|
|
|
|
to_s
|
2014-05-20 04:28:33 -04:00
|
|
|
to_i
|
2018-02-27 03:15:27 -05:00
|
|
|
to_f
|
2017-04-14 01:19:12 -04:00
|
|
|
to_r
|
2014-06-28 00:58:25 -04:00
|
|
|
bt
|
|
|
|
bt_locations
|
parse.y: optimize IDs in ripper
* parse.y: optimize ripper_intern calls, ::, **, -@, +@, <=>, >=,
<=, ==, ===, !=, =~, !~, <<, >>, and call.
* parse.y: use initialized IDs, warn and warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48153 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-27 02:23:09 -04:00
|
|
|
call
|
2014-11-16 03:33:35 -05:00
|
|
|
mesg
|
|
|
|
exception
|
2017-02-11 23:20:35 -05:00
|
|
|
not NOT
|
2017-02-12 03:33:33 -05:00
|
|
|
and AND
|
|
|
|
or OR
|
2019-08-02 19:37:08 -04:00
|
|
|
div
|
|
|
|
divmod
|
|
|
|
fdiv
|
|
|
|
quo
|
|
|
|
name
|
2019-09-01 00:37:28 -04:00
|
|
|
nil
|
2014-05-20 02:28:52 -04:00
|
|
|
|
2012-12-04 12:36:19 -05:00
|
|
|
_ UScore
|
|
|
|
"/*NULL*/" NULL
|
|
|
|
empty?
|
2013-05-02 03:54:17 -04:00
|
|
|
eql?
|
2012-12-04 12:36:19 -05:00
|
|
|
respond_to? Respond_to
|
|
|
|
respond_to_missing? Respond_to_missing
|
|
|
|
<IFUNC>
|
|
|
|
<CFUNC>
|
|
|
|
core#set_method_alias
|
|
|
|
core#set_variable_alias
|
|
|
|
core#undef_method
|
|
|
|
core#define_method
|
|
|
|
core#define_singleton_method
|
|
|
|
core#set_postexe
|
|
|
|
core#hash_merge_ptr
|
|
|
|
core#hash_merge_kwd
|
2019-04-17 02:48:03 -04:00
|
|
|
core#raise
|
2015-10-27 04:06:58 -04:00
|
|
|
|
2015-11-20 18:49:31 -05:00
|
|
|
- debug#created_info
|
2016-02-17 07:42:00 -05:00
|
|
|
|
|
|
|
$_ LASTLINE
|
|
|
|
$~ BACKREF
|
2019-04-10 08:43:34 -04:00
|
|
|
$! ERROR_INFO
|
2012-12-04 12:36:19 -05:00
|
|
|
]
|
|
|
|
|
2015-11-04 23:04:00 -05:00
|
|
|
# VM ID OP Parser Token
|
|
|
|
token_ops = %[\
|
|
|
|
Dot2 .. DOT2
|
|
|
|
Dot3 ... DOT3
|
2019-04-03 04:11:41 -04:00
|
|
|
BDot2 .. BDOT2
|
|
|
|
BDot3 ... BDOT3
|
2015-11-04 23:04:00 -05:00
|
|
|
UPlus +@ UPLUS
|
|
|
|
UMinus -@ UMINUS
|
|
|
|
Pow ** POW
|
|
|
|
Cmp <=> CMP
|
|
|
|
PLUS +
|
|
|
|
MINUS -
|
|
|
|
MULT *
|
|
|
|
DIV /
|
|
|
|
MOD %
|
|
|
|
LTLT << LSHFT
|
|
|
|
GTGT >> RSHFT
|
|
|
|
LT <
|
|
|
|
LE <= LEQ
|
|
|
|
GT >
|
|
|
|
GE >= GEQ
|
|
|
|
Eq == EQ
|
|
|
|
Eqq === EQQ
|
|
|
|
Neq != NEQ
|
|
|
|
Not !
|
2018-09-25 22:38:45 -04:00
|
|
|
And &
|
|
|
|
Or |
|
2015-11-04 23:04:00 -05:00
|
|
|
Backquote `
|
|
|
|
EqTilde =~ MATCH
|
|
|
|
NeqTilde !~ NMATCH
|
|
|
|
AREF []
|
|
|
|
ASET []=
|
|
|
|
COLON2 ::
|
|
|
|
ANDOP &&
|
|
|
|
OROP ||
|
2015-11-10 04:42:27 -05:00
|
|
|
ANDDOT &.
|
2018-12-31 10:00:37 -05:00
|
|
|
METHREF .:
|
2015-11-04 23:04:00 -05:00
|
|
|
]
|
|
|
|
|
2012-12-21 02:38:07 -05:00
|
|
|
class KeywordError < RuntimeError
|
|
|
|
def self.raise(mesg, line)
|
|
|
|
super(self, mesg, ["#{__FILE__}:#{line}", *caller])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-04 12:36:19 -05:00
|
|
|
predefined_ids = {}
|
|
|
|
preserved_ids = []
|
2012-12-21 02:38:03 -05:00
|
|
|
local_ids = []
|
|
|
|
instance_ids = []
|
|
|
|
global_ids = []
|
|
|
|
const_ids = []
|
|
|
|
class_ids = []
|
2014-11-14 01:55:05 -05:00
|
|
|
attrset_ids = []
|
2015-11-04 23:04:00 -05:00
|
|
|
token_op_ids = []
|
2012-12-21 02:38:03 -05:00
|
|
|
names = {}
|
2012-12-27 17:08:41 -05:00
|
|
|
predefined.split(/^/).each_with_index do |line, num|
|
2013-04-30 22:38:44 -04:00
|
|
|
next if /^#/ =~ line
|
|
|
|
line.sub!(/\s+#.*/, '')
|
|
|
|
name, token = line.split
|
|
|
|
next unless name
|
2012-12-04 12:36:19 -05:00
|
|
|
token ||= name
|
|
|
|
if /#/ =~ token
|
|
|
|
token = "_#{token.gsub(/\W+/, '_')}"
|
|
|
|
else
|
|
|
|
token = token.sub(/\?/, 'P').sub(/\A[a-z]/) {$&.upcase}
|
2012-12-21 02:38:03 -05:00
|
|
|
token.sub!(/\A\$/, "_G_")
|
|
|
|
token.sub!(/\A@@/, "_C_")
|
|
|
|
token.sub!(/\A@/, "_I_")
|
2012-12-04 12:36:19 -05:00
|
|
|
token.gsub!(/\W+/, "")
|
|
|
|
end
|
2015-10-27 10:14:18 -04:00
|
|
|
if name == '-'
|
|
|
|
preserved_ids << token
|
|
|
|
next
|
|
|
|
end
|
2012-12-21 02:38:07 -05:00
|
|
|
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
|
2012-12-21 02:38:03 -05:00
|
|
|
case name
|
|
|
|
when /\A[A-Z]\w*\z/; const_ids
|
|
|
|
when /\A(?!\d)\w+\z/; local_ids
|
2016-02-17 07:42:00 -05:00
|
|
|
when /\A\$(?:\d+|(?!\d)\w+|\W)\z/; global_ids
|
2012-12-21 02:38:03 -05:00
|
|
|
when /\A@@(?!\d)\w+\z/; class_ids
|
|
|
|
when /\A@(?!\d)\w+\z/; instance_ids
|
2014-11-14 01:55:05 -05:00
|
|
|
when /\A((?!\d)\w+)=\z/; attrset_ids
|
2012-12-21 02:38:03 -05:00
|
|
|
else preserved_ids
|
|
|
|
end << token
|
2012-12-04 12:36:19 -05:00
|
|
|
predefined_ids[token] = name
|
|
|
|
end
|
2015-11-04 23:04:00 -05:00
|
|
|
token_ops.split(/^/).each do |line|
|
|
|
|
next if /^#/ =~ line
|
|
|
|
line.sub!(/\s+#.*/, '')
|
|
|
|
id, op, token = line.split
|
|
|
|
next unless id and op
|
|
|
|
token ||= (id unless /\A\W\z/ =~ op)
|
|
|
|
token_op_ids << [id, op, token]
|
|
|
|
end
|
2012-12-21 02:38:03 -05:00
|
|
|
{
|
|
|
|
"LOCAL" => local_ids,
|
|
|
|
"INSTANCE" => instance_ids,
|
|
|
|
"GLOBAL" => global_ids,
|
|
|
|
"CONST" => const_ids,
|
|
|
|
"CLASS" => class_ids,
|
2014-11-14 01:55:05 -05:00
|
|
|
"ATTRSET" => attrset_ids,
|
2012-12-21 02:38:03 -05:00
|
|
|
:preserved => preserved_ids,
|
|
|
|
:predefined => predefined_ids,
|
2015-11-04 23:04:00 -05:00
|
|
|
:token_op => token_op_ids,
|
2012-12-21 02:38:03 -05:00
|
|
|
}
|