module PryCoolline::ParenMatch

Constants

AnsiCode
CloseToken
DanglingClose

A top-level closing paren — meaning there’s no matching opening character.

Leaf

A sequence of text on its own, that contains no parts of a pair.

@attr [StrToken] tok

Node

A block of code that was opened by a character, and may or may not (but should!) have been closed by another token.

@attr [OpenToken] open @attr [CloseToken, nil] close

@attr [Array<Leaf, Node>] elements Other nodes within the opening and

the closing tokens.
OpenToken
Pair

Represents a pair that should be matched.

@attr [OpenToken, nil] open @attr [CloseToken, nil] close

Pairs
StrToken
Token

A Token is a short chunk of code. This tokenizer only distinguishes three kinds of token:

1. Tokens that open a pair (OpenToken)
2. Tokens that close a pair (CloseToken)
3. The rest of the code (StrToken)

@attr [String] str String covered by the token @attr [Integer] pos Position in the initial code, character-wise,

disregarding ANSI codes.

@attr [Integer] code_pos Position in the initial code, character-wise,

including ANSI codes.

Public Instance Methods

pair_at(pos) click to toggle source

(see Root#pair_at)

# File lib/pry-coolline/paren_match.rb, line 152
def pair_at(pos)
  if pos == open.pos ||
      (close && pos == close.pos + close.str.size)
    Pair.new(open, close)
  else
    elements.each do |el|
      if pair = el.pair_at(pos)
        return pair
      end
    end

    nil
  end
end