Module: Rattler::Compiler::Optimizer

Extended by:
Optimizations, Parsers
Defined in:
lib/rattler/compiler/optimizer.rb,
lib/rattler/compiler/optimizer/flattening.rb,
lib/rattler/compiler/optimizer/optimization.rb,
lib/rattler/compiler/optimizer/match_joining.rb,
lib/rattler/compiler/optimizer/optimizations.rb,
lib/rattler/compiler/optimizer/flatten_choice.rb,
lib/rattler/compiler/optimizer/flatten_sequence.rb,
lib/rattler/compiler/optimizer/join_match_choice.rb,
lib/rattler/compiler/optimizer/optimize_children.rb,
lib/rattler/compiler/optimizer/composite_reducing.rb,
lib/rattler/compiler/optimizer/join_match_sequence.rb,
lib/rattler/compiler/optimizer/reduce_repeat_match.rb,
lib/rattler/compiler/optimizer/inline_regular_rules.rb,
lib/rattler/compiler/optimizer/join_predicate_match.rb,
lib/rattler/compiler/optimizer/optimization_context.rb,
lib/rattler/compiler/optimizer/simplify_token_match.rb,
lib/rattler/compiler/optimizer/optimization_sequence.rb,
lib/rattler/compiler/optimizer/join_predicate_or_match.rb,
lib/rattler/compiler/optimizer/join_predicate_bare_match.rb,
lib/rattler/compiler/optimizer/simplify_redundant_repeat.rb,
lib/rattler/compiler/optimizer/remove_meaningless_wrapper.rb,
lib/rattler/compiler/optimizer/join_predicate_nested_match.rb,
lib/rattler/compiler/optimizer/join_match_matching_sequence.rb,
lib/rattler/compiler/optimizer/join_predicate_or_bare_match.rb,
lib/rattler/compiler/optimizer/join_match_capturing_sequence.rb,
lib/rattler/compiler/optimizer/join_predicate_or_nested_match.rb

Overview

The Optimizer transforms parser models into equivalent models that can result in more efficient parsing code. This is primarily achieved by converting regular expressions into equivalent Regexp patterns, thus reducing object instantiation and method dispatch and having StringScanner do as much of the parsing work as possible.

Defined Under Namespace

Modules: CompositeReducing, Flattening, MatchJoining, Optimizations Classes: FlattenCapturingSequence, FlattenChoice, FlattenMatchingSequence, InlineRegularRules, JoinMatchCapturingSequence, JoinMatchChoice, JoinMatchMatchingSequence, JoinPredicateBareMatch, JoinPredicateNestedMatch, JoinPredicateOrBareMatch, JoinPredicateOrNestedMatch, Optimization, OptimizationContext, OptimizationSequence, OptimizeChildren, ReduceRepeatMatch, RemoveMeaninglessWrapper, SimplifyRedundantRepeat, SimplifyTokenMatch

Constant Summary collapse

FlattenSequence =

Nested sequence expressions can be flattened without affecting how they parse given certain conditions

FlattenMatchingSequence >> FlattenCapturingSequence
JoinMatchSequence =

Sequences of Regexp matches can be joined into a single Regexp match using capturing groups if necessary.

JoinMatchMatchingSequence >> JoinMatchCapturingSequence
JoinPredicateMatch =

A predicate and an adjacent Regexp match in a Sequence can be joined into a single Regexp match.

JoinPredicateBareMatch >> JoinPredicateNestedMatch
JoinPredicateOrMatch =

A predicate and an adjacent Regexp match in a Choice can be joined into a single Regexp match.

JoinPredicateOrBareMatch >> JoinPredicateOrNestedMatch

Class Method Summary collapse

Methods included from Optimizations

optimizations

Class Method Details

.optimize(model, opts = {}) ⇒ Object

Returns an optimized parser model.

Parameters:

Returns:

  • an optimized parser model



20
21
22
23
24
25
26
# File 'lib/rattler/compiler/optimizer.rb', line 20

def optimize(model, opts={})
  case model
  when Grammar then optimize_grammar model, opts
  when RuleSet then optimize_rule_set model, opts
  else optimizations.apply model, default_context(opts)
  end
end