class Rattler::Compiler::Optimizer::OptimizationContext

OptimizationContext provides contextual information to optimzations.

Attributes

rules[R]
type[R]

Public Class Methods

[](attrs) click to toggle source

@param [Hash] attrs attributes of an optimization context @return [OptimizationContext] an optimization context with the given

attributes
# File lib/rattler/compiler/optimizer/optimization_context.rb, line 14
def self.[](attrs)
  @@cache[attrs]
end
new(attrs) click to toggle source

@param [Hash] attrs attributes of an optimization context

# File lib/rattler/compiler/optimizer/optimization_context.rb, line 19
def initialize(attrs)
  @attrs = attrs
  @rules = @attrs[:rules]
end

Public Instance Methods

analysis() click to toggle source

@return [Rattler::Parsers::Analysis] an analysis of the parse rules

# File lib/rattler/compiler/optimizer/optimization_context.rb, line 32
def analysis
  rules && rules.analysis
end
capturing?() click to toggle source

@return whether this is a capturing context

# File lib/rattler/compiler/optimizer/optimization_context.rb, line 37
def capturing?
  @attrs[:type] == :capturing
end
inlineable?(rule_name) click to toggle source

@param [Symbol] rule_name the name of a rule in the context @return whether the rule can be inlined

# File lib/rattler/compiler/optimizer/optimization_context.rb, line 48
def inlineable?(rule_name)
  if rule = rules[rule_name]
    rule.attrs[:inline] and
    analysis.regular? rule_name
  end
end
matching?() click to toggle source

@return whether this is a matching context

# File lib/rattler/compiler/optimizer/optimization_context.rb, line 42
def matching?
  @attrs[:type] == :matching
end
relavent?(rule) click to toggle source

@param [Rattler::Parsers::Rule] rule a rule in the context @return whether the rule is relavent to the optimized parser

# File lib/rattler/compiler/optimizer/optimization_context.rb, line 57
def relavent?(rule)
  !rule.attrs[:inline] or
  analysis.referenced?(rule.name)
end
start_rule() click to toggle source

@return [Symbol] the name of the start rule

# File lib/rattler/compiler/optimizer/optimization_context.rb, line 27
def start_rule
  rules && rules.start_rule
end
with(new_attrs) click to toggle source

@param [Hash] new_attrs additional attributes @return [OptimizationContext] a new context with new_attrs added

# File lib/rattler/compiler/optimizer/optimization_context.rb, line 64
def with(new_attrs)
  self.class[@attrs.merge new_attrs]
end