Class: Regex::CapturingGroup
- Inherits:
-
MonadicExpression
- Object
- Expression
- CompoundExpression
- MonadicExpression
- Regex::CapturingGroup
- Defined in:
- lib/regex/capturing_group.rb
Overview
An association between a capture variable and an expression the subject text in the same serial arrangement
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
The capture variable id.
-
#no_backtrack ⇒ Object
readonly
When true, then capturing group forbids backtracking requests from its parent expression.
Attributes inherited from MonadicExpression
Attributes inherited from Expression
Instance Method Summary collapse
-
#initialize(aChildExpression, theId = nil, noBacktrack = false) ⇒ CapturingGroup
constructor
Constructor.
-
#named? ⇒ Boolean
Return true iff the capturing group has a name.
-
#to_str ⇒ Object
Conversion method re-definition.
Methods inherited from MonadicExpression
Methods inherited from CompoundExpression
Methods inherited from Expression
Constructor Details
#initialize(aChildExpression, theId = nil, noBacktrack = false) ⇒ CapturingGroup
Constructor.
25 26 27 28 29 |
# File 'lib/regex/capturing_group.rb', line 25 def initialize(aChildExpression, theId = nil, noBacktrack = false) super(aChildExpression) @id = theId @no_backtrack = noBacktrack end |
Instance Attribute Details
#id ⇒ Object (readonly)
The capture variable id. It is a Fixnum when the capture group gets a sequence number, a String when it is an user-defined name
12 13 14 |
# File 'lib/regex/capturing_group.rb', line 12 def id @id end |
#no_backtrack ⇒ Object (readonly)
When true, then capturing group forbids backtracking requests from its parent expression.
16 17 18 |
# File 'lib/regex/capturing_group.rb', line 16 def no_backtrack @no_backtrack end |
Instance Method Details
#named? ⇒ Boolean
Return true iff the capturing group has a name
32 33 34 |
# File 'lib/regex/capturing_group.rb', line 32 def named? id.kind_of?(String) end |
#to_str ⇒ Object
Conversion method re-definition. Purpose: Return the String representation of the captured expression.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/regex/capturing_group.rb', line 38 def to_str prefix = named? ? "?<#{id}>" : '' atomic = no_backtrack ? '?>' : '' if child.is_a?(Regex::NonCapturingGroup) # Minor optimization result = '(' + atomic + prefix + child.child.to_str + ')' else result = '(' + atomic + prefix + child.to_str + ')' end return result end |