Module: Rattler::Compiler::Optimizer::Flattening

Included in:
FlattenCapturingSequence, FlattenChoice, FlattenMatchingSequence
Defined in:
lib/rattler/compiler/optimizer/flattening.rb

Instance Method Summary collapse

Instance Method Details

#_applies_to?(parser, context) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


7
8
9
# File 'lib/rattler/compiler/optimizer/flattening.rb', line 7

def _applies_to?(parser, context)
  parser.any? {|_| eligible_child? _ }
end

#_apply(parser, context) ⇒ Object



11
12
13
14
# File 'lib/rattler/compiler/optimizer/flattening.rb', line 11

def _apply(parser, context)
  children = parser.map {|_| eligible_child?(_) ? _.to_a : [_] }.reduce(:+)
  parser.class.new(children, parser.attrs)
end