Class: Opencdd::Cddal::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/opencdd/cddal/builder.rb

Overview

Builds a Opencdd::Database from a parsed CDDAL AST. Owns the module/import pipeline: resolves specifiers via the configured Resolver, fetches sources via the Fetcher, recursively builds imported documents into the same database, tracks the dependency graph for cycle detection, and applies bare, qualified, and selective import scoping rules.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database = nil, resolver: nil, source_file: nil, loaded_modules: nil, loading_stack: nil) ⇒ Builder

Returns a new instance of Builder.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/opencdd/cddal/builder.rb', line 26

def initialize(database = nil, resolver: nil, source_file: nil,
               loaded_modules: nil, loading_stack: nil)
  @database = database || Opencdd::Database.new
  @resolver = resolver || Opencdd::Cddal.default_resolver
  @source_file = source_file
  @loaded_modules = loaded_modules || {}
  @loading_stack = loading_stack || []
  @alias_table = Opencdd::AliasTable.new(defaults: true)
  @symbol_table = {}
  @qualified_table = {} # "qualifier.name" => entity (qualified imports)
  @instance_decls = []
  @meta_class_overrides = {}
end

Instance Attribute Details

#alias_tableObject (readonly)

Returns the value of attribute alias_table.



23
24
25
# File 'lib/opencdd/cddal/builder.rb', line 23

def alias_table
  @alias_table
end

#databaseObject (readonly)

Returns the value of attribute database.



23
24
25
# File 'lib/opencdd/cddal/builder.rb', line 23

def database
  @database
end

#loaded_modulesObject (readonly)

Returns the value of attribute loaded_modules.



23
24
25
# File 'lib/opencdd/cddal/builder.rb', line 23

def loaded_modules
  @loaded_modules
end

#meta_class_overridesObject (readonly)

Returns the value of attribute meta_class_overrides.



23
24
25
# File 'lib/opencdd/cddal/builder.rb', line 23

def meta_class_overrides
  @meta_class_overrides
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



23
24
25
# File 'lib/opencdd/cddal/builder.rb', line 23

def source_file
  @source_file
end

#symbol_tableObject (readonly)

Returns the value of attribute symbol_table.



23
24
25
# File 'lib/opencdd/cddal/builder.rb', line 23

def symbol_table
  @symbol_table
end

Instance Method Details

#build(document_or_declarations) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/opencdd/cddal/builder.rb', line 40

def build(document_or_declarations)
  document = wrap_document(document_or_declarations)
  apply_alias_declarations(document)
  apply_meta_class_declarations(document)
  apply_import_declarations(document)
  register_instance_symbols(document)
  instantiate_entities(document)
  resolve_property_references(document)
  # Linking (parent/child, declared_property_irdis, value lists,
  # symbol table) lives in Database.finalize! — single source
  # of truth for entity-graph invariants. Builder used to
  # duplicate link_class_hierarchy / link_property_classes;
  # those were folded into Database#link_property_classes!
  # (which now runs both relation-based and definition_class-
  # based strategies).
  @database.finalize!
  @database
end

#peek_import(specifier) ⇒ Object

Resolve specifier and return its source text without building it into the database. Used by the validator and by diagnostics that want to peek at imports.



62
63
64
# File 'lib/opencdd/cddal/builder.rb', line 62

def peek_import(specifier)
  @resolver.resolve(specifier, importing_file: @source_file)
end