Class: Regexp::Parser
- Inherits:
-
Object
- Object
- Regexp::Parser
- Includes:
- Expression
- Defined in:
- lib/regexp_parser/parser.rb,
lib/regexp_parser/version.rb,
lib/regexp_parser/error.rb
Defined Under Namespace
Classes: Error, ParserError, UnknownTokenError, UnknownTokenTypeError
Constant Summary collapse
- VERSION =
'2.8.3'
Constants included from Expression
Expression::Backref, Expression::Escape, Expression::MatchLength, Expression::Nonposixclass, Expression::Nonproperty, Expression::Posixclass, Expression::Property, Expression::Set
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.parse(input, syntax = nil, options: nil, &block) ⇒ Object
21 22 23 |
# File 'lib/regexp_parser/parser.rb', line 21 def self.parse(input, syntax = nil, options: nil, &block) new.parse(input, syntax, options: , &block) end |
Instance Method Details
#parse(input, syntax = nil, 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 50 51 52 |
# File 'lib/regexp_parser/parser.rb', line 25 def parse(input, syntax = nil, options: nil, &block) root = Root.construct(options: (input, )) self.root = root self.node = root self.nesting = [root] self. = [root.] self. = false self.conditional_nesting = [] self.captured_group_counts = Hash.new(0) Regexp::Lexer.scan(input, syntax, 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 |