Class: PryCoolline::ParenMatch::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/pry-coolline/paren_match.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, pairs = Pairs) ⇒ Parser

Returns a new instance of Parser.

Parameters:

  • code (String)
  • pos (Integer)

    Position of the selected character, disregarding ANSI codes.

  • pairs (Hash<String, String>) (defaults to: Pairs)

    A hash mapping each opening character to a closing one.



178
179
180
# File 'lib/pry-coolline/paren_match.rb', line 178

def initialize(code, pairs = Pairs)
  @tokens = tokenize(code, pairs)
end

Class Method Details

.parse(code, pairs = Pairs) ⇒ AST::Root

Parameters:

  • code (String)
  • pos (Integer)

    Position of the selected character, disregarding ANSI codes.

  • pairs (Hash<String, String>) (defaults to: Pairs)

    A hash mapping each opening character to a closing one.

Returns:



173
174
175
# File 'lib/pry-coolline/paren_match.rb', line 173

def self.parse(code, pairs = Pairs)
  new(code, pairs).parse
end

Instance Method Details

#next_tokenToken

Returns the next token found in the array and removes it.

Returns:

  • (Token)

    The next token, which will be removed from the queue.



190
191
192
# File 'lib/pry-coolline/paren_match.rb', line 190

def next_token
  @tokens.shift
end

#parseAST::Root

Returns:



183
184
185
# File 'lib/pry-coolline/paren_match.rb', line 183

def parse
  AST::Root.new self
end