Class: Opencdd::Cddal::Builder
- Inherits:
-
Object
- Object
- Opencdd::Cddal::Builder
- 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
-
#alias_table ⇒ Object
readonly
Returns the value of attribute alias_table.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#loaded_modules ⇒ Object
readonly
Returns the value of attribute loaded_modules.
-
#meta_class_overrides ⇒ Object
readonly
Returns the value of attribute meta_class_overrides.
-
#source_file ⇒ Object
readonly
Returns the value of attribute source_file.
-
#symbol_table ⇒ Object
readonly
Returns the value of attribute symbol_table.
Instance Method Summary collapse
- #build(document_or_declarations) ⇒ Object
-
#initialize(database = nil, resolver: nil, source_file: nil, loaded_modules: nil, loading_stack: nil) ⇒ Builder
constructor
A new instance of Builder.
-
#peek_import(specifier) ⇒ Object
Resolve
specifierand return its source text without building it into the database.
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_table ⇒ Object (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 |
#database ⇒ Object (readonly)
Returns the value of attribute database.
23 24 25 |
# File 'lib/opencdd/cddal/builder.rb', line 23 def database @database end |
#loaded_modules ⇒ Object (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_overrides ⇒ Object (readonly)
Returns the value of attribute meta_class_overrides.
23 24 25 |
# File 'lib/opencdd/cddal/builder.rb', line 23 def @meta_class_overrides end |
#source_file ⇒ Object (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_table ⇒ Object (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) (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 |