Class: Ruby::Rego::Parser::BracketMatcher
- Inherits:
-
Object
- Object
- Ruby::Rego::Parser::BracketMatcher
- Defined in:
- lib/ruby/rego/parser/rules.rb
Overview
Finds matching closing brackets for rule head path segments.
Constant Summary collapse
Instance Method Summary collapse
-
#initialize(token_provider:) ⇒ BracketMatcher
constructor
A new instance of BracketMatcher.
-
#matching_index(start_index) ⇒ Integer?
:reek:FeatureEnvy.
Constructor Details
#initialize(token_provider:) ⇒ BracketMatcher
Returns a new instance of BracketMatcher.
361 362 363 |
# File 'lib/ruby/rego/parser/rules.rb', line 361 def initialize(token_provider:) @token_provider = token_provider end |
Instance Method Details
#matching_index(start_index) ⇒ Integer?
:reek:FeatureEnvy
368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/ruby/rego/parser/rules.rb', line 368 def matching_index(start_index) depth = 0 loop do token_type = token_provider.call(start_index).type return nil if token_type == TokenType::EOF depth += BRACKET_DEPTH_DELTA.fetch(token_type, 0) return start_index if token_type == TokenType::RBRACKET && depth.zero? start_index += 1 end end |