Class: MiniKraken::Core::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_kraken/core/scope.rb

Overview

A scope is a name space that corresponds either to a specific delimited region in MiniKraken source code or to an activation record of a relation or a relation definition. It contains a map of names to the objects they name (e.g. logical var)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aParent = nil) ⇒ Scope

Construct a scope instance. TODO: extend with defrel and procedure

Parameters:

  • aParent (Scope, NilClass) (defaults to: nil)

    Parent scope to this one.



24
25
26
27
# File 'lib/mini_kraken/core/scope.rb', line 24

def initialize(aParent = nil)
  @parent = aParent
  @defns = {}
end

Instance Attribute Details

#defnsHash{String => LogVar} (readonly)

Mapping from user-defined name to related definition

(say, a logical variable object)

Returns:

  • (Hash{String => LogVar})

    Pairs of the kind



19
20
21
# File 'lib/mini_kraken/core/scope.rb', line 19

def defns
  @defns
end

#parentScope, NilClass

The parent (enclosing) scope.

Returns:



14
15
16
# File 'lib/mini_kraken/core/scope.rb', line 14

def parent
  @parent
end

Instance Method Details

#insert(anEntry) ⇒ LogVar

Add a new logical variable to the scope.

Parameters:

Returns:



32
33
34
35
36
37
38
# File 'lib/mini_kraken/core/scope.rb', line 32

def insert(anEntry)
  e = validated_entry(anEntry)
  e.suffix = default_suffix if e.kind_of?(LogVar)
  defns[e.name] = e

  e
end

#inspectString

Returns a string with a human-readable representation of the object.

Returns:

  • (String)


42
43
44
# File 'lib/mini_kraken/core/scope.rb', line 42

def inspect
  +"#<#{self.class}:#{object_id.to_s(16)}>"
end