class Rattler::Compiler::Optimizer::SimplifyRedundantRepeat

A repeat of a repeat can be simplified to a simple repeat.

Protected Instance Methods

_applies_to?(parser, context) click to toggle source
# File lib/rattler/compiler/optimizer/simplify_redundant_repeat.rb, line 12
def _applies_to?(parser, context)
  context.matching? and
  [parser, parser.child].all? {|_| simple_repeat? _ }
end
_apply(parser, context) click to toggle source
# File lib/rattler/compiler/optimizer/simplify_redundant_repeat.rb, line 17
def _apply(parser, context)
  if (parser.zero_or_more? and parser.child.zero_or_more?) or
      (parser.one_or_more? and parser.child.one_or_more?) or
      (parser.optional? and parser.child.optional?)
    parser.child
  else
    Repeat[parser.child.child, 0, nil]
  end
end

Private Instance Methods

simple_repeat?(parser) click to toggle source
# File lib/rattler/compiler/optimizer/simplify_redundant_repeat.rb, line 29
def simple_repeat?(parser)
  parser.is_a? Repeat and
  ( parser.zero_or_more? or
    parser.one_or_more? or
    parser.optional? )
end