Class: Calyx::Production::Memo

Inherits:
Object
  • Object
show all
Defined in:
lib/calyx/production/memo.rb

Overview

A type of production rule representing a memoized subsitution which returns the first value selected on all subsequent lookups.

Constant Summary collapse

SIGIL =
'@'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(symbol, registry) ⇒ Memo

Construct a memoized rule, given the symbol to lookup and the registry to look it up in.

Parameters:



13
14
15
16
# File 'lib/calyx/production/memo.rb', line 13

def initialize(symbol, registry)
  @symbol = symbol.slice(1, symbol.length-1).to_sym
  @registry = registry
end

Instance Method Details

#evaluate(rng) ⇒ Array

Evaluate the memo, using the registry to handle the expansion.

Returns:

  • (Array)


21
22
23
# File 'lib/calyx/production/memo.rb', line 21

def evaluate(rng)
  [@symbol, @registry.memoize_expansion(@symbol)]
end