Class: Calyx::Syntax::Memo

Inherits:
Object
  • Object
show all
Defined in:
lib/calyx/syntax/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/syntax/memo.rb', line 13

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

Instance Method Details

#evaluate(options) ⇒ Array

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

Parameters:

Returns:

  • (Array)


22
23
24
# File 'lib/calyx/syntax/memo.rb', line 22

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