Class: Regexp::Parser

Inherits:
Object
  • Object
show all
Includes:
Expression, Expression::UnicodeProperty, Syntax
Defined in:
lib/regexp_parser/parser.rb,
lib/regexp_parser/version.rb

Defined Under Namespace

Classes: ParserError, UnknownTokenError, UnknownTokenTypeError

Constant Summary collapse

VERSION =
'2.0.3'

Constants included from Syntax

Syntax::VERSION_CONST_REGEXP, Syntax::VERSION_FORMAT, Syntax::VERSION_REGEXP

Constants included from Expression

Expression::MatchLength

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Syntax

comparable_version, const_missing, fallback_version_class, inherit_from_version, new, specified_versions, supported?, version_class, version_const_name, warn_if_future_version

Class Method Details

.parse(input, syntax = "ruby/#{RUBY_VERSION}", options: nil, &block) ⇒ Object



21
22
23
# File 'lib/regexp_parser/parser.rb', line 21

def self.parse(input, syntax = "ruby/#{RUBY_VERSION}", options: nil, &block)
  new.parse(input, syntax, options: options, &block)
end

Instance Method Details

#parse(input, syntax = "ruby/#{RUBY_VERSION}", options: nil, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/regexp_parser/parser.rb', line 25

def parse(input, syntax = "ruby/#{RUBY_VERSION}", options: nil, &block)
  root = Root.build(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) do |token|
    parse_token(token)
  end

  assign_referenced_expressions

  if block_given?
    block.call(root)
  else
    root
  end
end