Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3a97ae77f002
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c95943a602d8
Choose a head ref
  • 2 commits
  • 9 files changed
  • 1 contributor

Commits on Feb 24, 2018

  1. Add ripper to sync files.

    headius committed Feb 24, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    headius Charles Oliver Nutter
    Copy the full SHA
    70df7cb View commit details
  2. Update stdlib.

    headius committed Feb 24, 2018
    Copy the full SHA
    c95943a View commit details
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/resolv.rb
Original file line number Diff line number Diff line change
@@ -771,7 +771,7 @@ def sender(msg, data, host, port=Port)
sock = @socks_hash[host.index(':') ? "::" : "0.0.0.0"]
return nil if !sock
service = [IPAddr.new(host), port]
id = DNS.allocate_request_id(service[0], service[1])
id = DNS.allocate_request_id(host, port)
request = msg.encode
request[0,2] = [id].pack('n')
return @senders[[service, id]] =
9 changes: 5 additions & 4 deletions lib/ruby/stdlib/ripper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'ripper/core'
require 'ripper/lexer'
require 'ripper/filter'
@@ -65,9 +66,9 @@
#
# == License
#
# Ruby License.
# Ruby License.
#
# Minero Aoki
# aamine@loveruby.net
# http://i.loveruby.net
# - Minero Aoki
# - aamine@loveruby.net
# - http://i.loveruby.net
class Ripper; end
23 changes: 12 additions & 11 deletions lib/ruby/stdlib/ripper/core.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# $Id$
#
@@ -34,16 +34,21 @@ def Ripper.parse(src, filename = '(ripper)', lineno = 1)

private

def _dispatch_0() nil end
def _dispatch_1(a) a end
def _dispatch_2(a, b) a end
def _dispatch_3(a, b, c) a end
def _dispatch_4(a, b, c, d) a end
def _dispatch_5(a, b, c, d, e) a end
def _dispatch_6(a, b, c, d, e, f) a end
def _dispatch_7(a, b, c, d, e, f, g) a end

#
# Parser Events
#

PARSER_EVENT_TABLE.each do |id, arity|
module_eval(<<-End, __FILE__, __LINE__ + 1)
def on_#{id}(#{ ('a'..'z').to_a[0, arity].join(', ') })
#{arity == 0 ? 'nil' : 'a'}
end
End
alias_method "on_#{id}", "_dispatch_#{arity}"
end

# This method is called when weak warning is produced by the parser.
@@ -65,11 +70,7 @@ def compile_error(msg)
#

SCANNER_EVENTS.each do |id|
module_eval(<<-End, __FILE__, __LINE__ + 1)
def on_#{id}(token)
token
end
End
alias_method "on_#{id}", :_dispatch_1
end

end
12 changes: 10 additions & 2 deletions lib/ruby/stdlib/ripper/filter.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# $Id$
#
@@ -25,6 +25,7 @@ def initialize(src, filename = '-', lineno = 1)
@__lexer = Lexer.new(src, filename, lineno)
@__line = nil
@__col = nil
@__state = nil
end

# The file name of the input.
@@ -46,13 +47,20 @@ def column
@__col
end

# The scanner's state of the current token.
# This value is the bitwise OR of zero or more of the +Ripper::EXPR_*+ constants.
def state
@__state
end

# Starts the parser.
# +init+ is a data accumulator and is passed to the next event handler (as
# of Enumerable#inject).
def parse(init = nil)
data = init
@__lexer.lex.each do |pos, event, tok|
@__lexer.lex.each do |pos, event, tok, state|
@__line, @__col = *pos
@__state = state
data = if respond_to?(event, true)
then __send__(event, tok, data)
else on_default(event, tok, data)
74 changes: 52 additions & 22 deletions lib/ruby/stdlib/ripper/lexer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# $Id$
#
@@ -23,29 +23,47 @@ def Ripper.tokenize(src, filename = '-', lineno = 1)
end

# Tokenizes the Ruby program and returns an array of an array,
# which is formatted like <code>[[lineno, column], type, token]</code>.
# which is formatted like
# <code>[[lineno, column], type, token, state]</code>.
#
# require 'ripper'
# require 'pp'
#
# pp Ripper.lex("def m(a) nil end")
# #=> [[[1, 0], :on_kw, "def"],
# [[1, 3], :on_sp, " " ],
# [[1, 4], :on_ident, "m" ],
# [[1, 5], :on_lparen, "(" ],
# [[1, 6], :on_ident, "a" ],
# [[1, 7], :on_rparen, ")" ],
# [[1, 8], :on_sp, " " ],
# [[1, 9], :on_kw, "nil"],
# [[1, 12], :on_sp, " " ],
# [[1, 13], :on_kw, "end"]]
# #=> [[[1, 0], :on_kw, "def", Ripper::EXPR_FNAME ],
# [[1, 3], :on_sp, " ", Ripper::EXPR_FNAME ],
# [[1, 4], :on_ident, "m", Ripper::EXPR_ENDFN ],
# [[1, 5], :on_lparen, "(", Ripper::EXPR_LABEL | Ripper::EXPR_BEG],
# [[1, 6], :on_ident, "a", Ripper::EXPR_ARG ],
# [[1, 7], :on_rparen, ")", Ripper::EXPR_ENDFN ],
# [[1, 8], :on_sp, " ", Ripper::EXPR_BEG ],
# [[1, 9], :on_kw, "nil", Ripper::EXPR_END ],
# [[1, 12], :on_sp, " ", Ripper::EXPR_END ],
# [[1, 13], :on_kw, "end", Ripper::EXPR_END ]]
#
def Ripper.lex(src, filename = '-', lineno = 1)
Lexer.new(src, filename, lineno).lex
end

class Lexer < ::Ripper #:nodoc: internal use only
Elem = Struct.new(:pos, :event, :tok)
State = Struct.new(:to_int, :to_s) do
alias to_i to_int
def initialize(i) super(i, Ripper.lex_state_name(i)).freeze end
def inspect; "#<#{self.class}: #{self}>" end
def pretty_print(q) q.text(to_s) end
def ==(i) super or to_int == i end
def &(i) self.class.new(to_int & i) end
def |(i) self.class.new(to_int & i) end
def allbits?(i) to_int.allbits?(i) end
def anybits?(i) to_int.anybits?(i) end
def nobits?(i) to_int.nobits?(i) end
end

Elem = Struct.new(:pos, :event, :tok, :state) do
def initialize(pos, event, tok, state)
super(pos, event, tok, State.new(state))
end
end

def tokenize
parse().sort_by(&:pos).map(&:tok)
@@ -66,13 +84,25 @@ def parse
private

def on_heredoc_dedent(v, w)
@buf.last.each do |e|
if e.event == :on_tstring_content
ignored_sp = []
heredoc = @buf.last
heredoc.each_with_index do |e, i|
if Elem === e and e.event == :on_tstring_content and e.pos[1].zero?
tok = e.tok.dup if w > 0 and /\A\s/ =~ e.tok
if (n = dedent_string(e.tok, w)) > 0
if e.tok.empty?
e.tok = tok[0, n]
e.event = :on_ignored_sp
next
end
ignored_sp << [i, Elem.new(e.pos.dup, :on_ignored_sp, tok[0, n], e.state)]
e.pos[1] += n
end
end
end
ignored_sp.reverse_each do |i, e|
heredoc[i, 0] = [e]
end
v
end

@@ -81,20 +111,20 @@ def on_heredoc_beg(tok)
buf = []
@buf << buf
@buf = buf
@buf.push Elem.new([lineno(), column()], __callee__, tok)
@buf.push Elem.new([lineno(), column()], __callee__, tok, state())
end

def on_heredoc_end(tok)
@buf.push Elem.new([lineno(), column()], __callee__, tok)
@buf.push Elem.new([lineno(), column()], __callee__, tok, state())
@buf = @stack.pop
end

def _push_token(tok)
@buf.push Elem.new([lineno(), column()], __callee__, tok, state())
end

(SCANNER_EVENTS.map {|event|:"on_#{event}"} - private_instance_methods(false)).each do |event|
module_eval(<<-End, __FILE__+'/module_eval', __LINE__ + 1)
def #{event}(tok)
@buf.push Elem.new([lineno(), column()], :#{event}, tok)
end
End
alias_method event, :_push_token
end
end

43 changes: 27 additions & 16 deletions lib/ruby/stdlib/ripper/sexp.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# $Id$
#
@@ -125,23 +125,34 @@ def on_heredoc_dedent(val, width)
val
end

def _dispatch_event_new
[]
end

def _dispatch_event_push(list, item)
list.push item
list
end

def on_mlhs_paren(list)
[:mlhs, *list]
end

def on_mlhs_add_star(list, star)
list.push([:rest_param, star])
end

def on_mlhs_add_post(list, post)
list.concat(post)
end

PARSER_EVENT_TABLE.each do |event, arity|
if /_new\z/ =~ event.to_s and arity == 0
module_eval(<<-End, __FILE__, __LINE__ + 1)
def on_#{event}
[]
end
End
elsif /_add\z/ =~ event.to_s
module_eval(<<-End, __FILE__, __LINE__ + 1)
def on_#{event}(list, item)
list.push item
list
end
End
if /_new\z/ =~ event and arity == 0
alias_method "on_#{event}", :_dispatch_event_new
elsif /_add\z/ =~ event
alias_method "on_#{event}", :_dispatch_event_push
end
end
end
end


end
3 changes: 0 additions & 3 deletions lib/ruby/stdlib/socket.rb
Original file line number Diff line number Diff line change
@@ -271,9 +271,6 @@ def connect_address
addr
end

# # JRuby does not do this dance to get around keyword arguments.
# unless RUBY_ENGINE == 'jruby'
#
# call-seq:
# basicsocket.sendmsg(mesg, flags=0, dest_sockaddr=nil, *controls) => numbytes_sent
#
51 changes: 2 additions & 49 deletions lib/ruby/stdlib/weakref.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require "delegate"

# Weak Reference class that allows a referenced object to be
@@ -15,53 +15,6 @@
# GC.start # start the garbage collector
# p foo.to_s # should raise exception (recycled)
#
# == Example
#
# With help from WeakRef, we can implement our own rudimentary WeakHash class.
#
# We will call it WeakHash, since it's really just a Hash except all of it's
# keys and values can be garbage collected.
#
# require 'weakref'
#
# class WeakHash < Hash
# def []= key, obj
# super WeakRef.new(key), WeakRef.new(obj)
# end
# end
#
# This is just a simple implementation, we've opened the Hash class and changed
# Hash#store to create a new WeakRef object with +key+ and +obj+ parameters
# before passing them as our key-value pair to the hash.
#
# With this you will have to limit your self to String keys, otherwise you
# will get an ArgumentError because WeakRef cannot create a finalizer for a
# Symbol. Symbols are immutable and cannot be garbage collected.
#
# Let's see it in action:
#
# omg = "lol"
# c = WeakHash.new
# c['foo'] = "bar"
# c['baz'] = Object.new
# c['qux'] = omg
# puts c.inspect
# #=> {"foo"=>"bar", "baz"=>#<Object:0x007f4ddfc6cb48>, "qux"=>"lol"}
#
# # Now run the garbage collector
# GC.start
# c['foo'] #=> nil
# c['baz'] #=> nil
# c['qux'] #=> nil
# omg #=> "lol"
#
# puts c.inspect
# #=> WeakRef::RefError: Invalid Reference - probably recycled
#
# You can see the local variable +omg+ stayed, although its reference in our
# hash object was garbage collected, along with the rest of the keys and
# values. Also, when we tried to inspect our hash, we got a WeakRef::RefError.
# This is because these objects were also garbage collected.

class WeakRef < Delegator

@@ -78,7 +31,7 @@ class RefError < StandardError
# Creates a weak reference to +orig+
#
# Raises an ArgumentError if the given +orig+ is immutable, such as Symbol,
# Fixnum, or Float.
# Integer, or Float.

def initialize(orig)
case orig
4 changes: 3 additions & 1 deletion tool/sync_ruby_files.rb
Original file line number Diff line number Diff line change
@@ -81,5 +81,7 @@
'ext/socket/lib/socket.rb' => 'socket.rb',
'ext/win32/lib/win32' => 'win32',
'ext/fiddle/lib/fiddle.rb' => 'fiddle.rb',
'ext/fiddle/lib/fiddle' => 'fiddle'
'ext/fiddle/lib/fiddle' => 'fiddle',
'ext/ripper/lib/ripper' => 'ripper',
'ext/ripper/lib/ripper.rb' => 'ripper.rb'
}