/usr/lib/ruby/vendor_ruby/rspec/core/source/token.rb is in ruby-rspec-core 3.5.0c3e0m0s0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | RSpec::Support.require_rspec_core "source/location"
module RSpec
module Core
class Source
# @private
# A wrapper for Ripper token which is generated with `Ripper.lex`.
class Token
CLOSING_TYPES_BY_OPENING_TYPE = {
:on_lbracket => :on_rbracket,
:on_lparen => :on_rparen,
:on_lbrace => :on_rbrace,
:on_heredoc_beg => :on_heredoc_end
}.freeze
CLOSING_KEYWORDS_BY_OPENING_KEYWORD = {
'def' => 'end',
'do' => 'end',
}.freeze
attr_reader :token
def self.tokens_from_ripper_tokens(ripper_tokens)
ripper_tokens.map { |ripper_token| new(ripper_token) }.freeze
end
def initialize(ripper_token)
@token = ripper_token.freeze
end
def location
@location ||= Location.new(*token[0])
end
def type
token[1]
end
def string
token[2]
end
def ==(other)
token == other.token
end
alias_method :eql?, :==
def inspect
"#<#{self.class} #{type} #{string.inspect}>"
end
def keyword?
type == :on_kw
end
def opening?
opening_delimiter? || opening_keyword?
end
def closed_by?(other)
closed_by_delimiter?(other) || closed_by_keyword?(other)
end
private
def opening_delimiter?
CLOSING_TYPES_BY_OPENING_TYPE.key?(type)
end
def opening_keyword?
return false unless keyword?
CLOSING_KEYWORDS_BY_OPENING_KEYWORD.key?(string)
end
def closed_by_delimiter?(other)
other.type == CLOSING_TYPES_BY_OPENING_TYPE[type]
end
def closed_by_keyword?(other)
return false unless other.keyword?
other.string == CLOSING_KEYWORDS_BY_OPENING_KEYWORD[string]
end
end
end
end
end
|