class Regexp::Parser
def parse(input, syntax = nil, options: nil, &block)
def parse(input, syntax = nil, options: nil, &block) root = Root.construct(options: extract_options(input, options)) self.root = root self.node = root self.nesting = [root] self.options_stack = [root.options] self.switching_options = false self.conditional_nesting = [] self.captured_group_counts = Hash.new(0) Regexp::Lexer.scan(input, syntax, options: options, collect_tokens: false) do |token| parse_token(token) end # Trigger recursive setting of #nesting_level, which reflects how deep # a node is in the tree. Do this at the end to account for tree rewrites. root.nesting_level = 0 assign_referenced_expressions if block_given? block.call(root) else root end end