Class: Ruby::Rego::Parser::BracketMatcher
- Inherits:
-
Object
- Object
- Ruby::Rego::Parser::BracketMatcher
- Defined in:
- lib/ruby/rego/parser/rule_head_builders.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?
Constructor Details
#initialize(token_provider:) ⇒ BracketMatcher
Returns a new instance of BracketMatcher.
62 63 64 |
# File 'lib/ruby/rego/parser/rule_head_builders.rb', line 62 def initialize(token_provider:) @token_provider = token_provider end |
Instance Method Details
#matching_index(start_index) ⇒ Integer?
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ruby/rego/parser/rule_head_builders.rb', line 68 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 |