Class: ActiveFacts::CQL::Compiler::CompilationContext

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/cql/compiler/shared.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vocabulary) ⇒ CompilationContext

Returns a new instance of CompilationContext.



49
50
51
52
53
54
55
56
# File 'lib/activefacts/cql/compiler/shared.rb', line 49

def initialize vocabulary
  @vocabulary = vocabulary
  @vocabulary_identifier = @vocabulary.identifying_role_values
  @allowed_forward_terms = []
  @bindings = {}
  @player_by_role_name = {}
  @left_contraction_allowed = false
end

Instance Attribute Details

#allowed_forward_termsObject

Returns the value of attribute allowed_forward_terms.



42
43
44
# File 'lib/activefacts/cql/compiler/shared.rb', line 42

def allowed_forward_terms
  @allowed_forward_terms
end

#bindingsObject (readonly)

The Bindings in this declaration



46
47
48
# File 'lib/activefacts/cql/compiler/shared.rb', line 46

def bindings
  @bindings
end

#left_contractable_clauseObject

Returns the value of attribute left_contractable_clause.



44
45
46
# File 'lib/activefacts/cql/compiler/shared.rb', line 44

def left_contractable_clause
  @left_contractable_clause
end

#left_contraction_allowedObject

Returns the value of attribute left_contraction_allowed.



43
44
45
# File 'lib/activefacts/cql/compiler/shared.rb', line 43

def left_contraction_allowed
  @left_contraction_allowed
end

#left_contraction_conjunctionObject

Returns the value of attribute left_contraction_conjunction.



45
46
47
# File 'lib/activefacts/cql/compiler/shared.rb', line 45

def left_contraction_conjunction
  @left_contraction_conjunction
end

#player_by_role_nameObject (readonly)

Returns the value of attribute player_by_role_name.



47
48
49
# File 'lib/activefacts/cql/compiler/shared.rb', line 47

def player_by_role_name
  @player_by_role_name
end

#vocabularyObject

Returns the value of attribute vocabulary.



41
42
43
# File 'lib/activefacts/cql/compiler/shared.rb', line 41

def vocabulary
  @vocabulary
end

Instance Method Details

#bind(*clauses) ⇒ Object

Pass in an array of clauses or References for player identification and binding (creating the Bindings) It’s necessary to identify all players that define a role name first, so those names exist in the context for where they’re used.



77
78
79
80
81
82
# File 'lib/activefacts/cql/compiler/shared.rb', line 77

def bind *clauses
  cl = clauses.flatten
  cl.each { |clause| clause.identify_players_with_role_name(self) }
  cl.each { |clause| clause.identify_other_players(self) }
  cl.each { |clause| clause.bind(self) }
end

#object_type(name) ⇒ Object

Look up this object_type by its name



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/activefacts/cql/compiler/shared.rb', line 59

def object_type(name)
  constellation = @vocabulary.constellation
  player = constellation.ObjectType[[@vocabulary_identifier, name]]

  # Bind to an existing role which has a role name (that's why we bind those first)
  player ||= @player_by_role_name[name]

  if !player && @allowed_forward_terms.include?(name)
	    @vocabulary.valid_entity_type_name(name)  # No need for the result here, just no exceptional condition
    player = constellation.EntityType(@vocabulary, name, :concept => :new)
  end

  player
end