aac.context.language_context

The LanguageContext is a singleton that holds the current state of the AaC language, including all definitions and plugin runners.

Classes

LanguageContext()

A singleton class that holds the current state of the AaC language.

class aac.context.language_context.LanguageContext[source]

A singleton class that holds the current state of the AaC language.

static __new__(cls)[source]

Create a new instance of the LanguageContext singleton class.

create_aac_enum(aac_enum_name: str, value: str) Any[source]

Function to create a Python enum for an AaC enum class and value.

Parameters:
  • aac_enum_name (str) – The name of the AaC Enum class.

  • value (str) – The value for the enum.

Returns:

A Python enum set to the specified value.

Raises:

LanguageError – When a unique definition for the AaC Enum is not found, an error message detailing the issue is generated.

Return type:

Any

create_aac_object(aac_type_name: str, attributes: dict) Any[source]

Function to create a Python object representation of an AaC class and its attributes.

Parameters:
  • aac_type_name (str) – The name of the AaC class.

  • attributes (dict) – A dictionary of attributes for the AaC class.

Returns:

A Python object representing the AaC class.

Raises:

LanguageError – When a unique definition for the AaC type is not found, an error message detailing the issue is generated.

Return type:

Any

get_aac_core_as_yaml() str[source]

Function to return the AaC language as a YAML string.

Returns:

The core AaC definitions file as a string in YAML format.

Return type:

str

get_aac_core_definitions() list[Definition][source]

Function to return the definitions for the AaC language.

Returns:

A list of definitions in the core AaC definitions file.

Return type:

list[Definition]

get_aac_core_file_path() str[source]

Function to return the AaC language file path.

Returns:

The filepath to the core AaC definitions file as a string.

Return type:

str

get_defining_schema_for_root(root_key: str) Definition[source]

Get the defining schema for a given root key.

Parameters:

root_key (str) – The root key for the schema definition.

Returns:

The definition of the root schema.

Raises:

LanguageError – When no definition is found for the defining schema, an error message detailing the issue is generated.

Return type:

Definition

get_definitions() list[Definition][source]

Get all the definitions.

Returns:

A list of all Definitions currently loaded into the Language Context.

Return type:

list[Definition]

get_definitions_by_name(name: str) list[Definition][source]

Get all the definitions with a given name.

Parameters:

name (str) – The name of the definition(s).

Returns:

A list of definitions with the given name.

Return type:

list[Definition]

get_definitions_by_root(root_key: str) list[Definition][source]

Get all the definitions with a given root key.

Parameters:

root_key (str) – A root key to search for.

Returns:

A list of definitions with the given root key.

Return type:

list[Definition]

get_definitions_of_type(package: str, name: str) list[Definition][source]

Search the language context to find definitions that match a given package and name.

Parameters:
  • package (str) – The package name of the type.

  • name (str) – The name of the type.

Returns:

A list of definitions of the specified type within the specified package.

Raises:

LanguageError – When no definition is found with the given name within the given package, an error message detailing the issue is generated.

Return type:

list[Definition]

get_plugin_runners() list[PluginRunner][source]

Get all the plugin runners.

Returns:

A list of all registered plugin runners.

Return type:

list[PluginRunner]

get_primitives() list[Definition][source]

Get all the primitive definitions.

Returns:

A list of all primitive definitions.

Return type:

list[Definition]

get_python_type_from_primitive(primitive_name: str) str[source]

Get the Python type from a primitive name.

Parameters:

primitive_name (str) – name of the primitive type.

Returns:

The Python type equivalent to the declared primitive type.

Raises:

LanguageError – When no primitive type is found with the given name, an error message detailing the issue is generated.

Return type:

str

get_values_by_field_chain(search_term: str) list[source]

Find values from the language context using a dot notation field chain.

Parameters:

search_term (str) – A dot notation field chain. (i.e. root.definition.field)

Returns:

A list of values from the specified fields.

Return type:

list

is_aac_instance(obj: Any, name: str) bool[source]

Function to determine if an object is an instance of an AaC class.

Parameters:
  • obj (Any) – Object to check.

  • name (str) – The AaC class name to be used for comparison.

Returns:

A boolean which equals true if the object is an instance of the specified class.

Return type:

bool

is_extension_of(check_me: Definition, package: str, name: str) bool[source]

Check to see if a given definition extends from a given package and name.

Parameters:
  • check_me (Definition) – The definition to be checked if it is an extension.

  • package (str) – The package name of the definitions to be checked against.

  • name (str) – The name of the definitions to be checked against.

Returns:

A boolean value which equals True if the given definition is an extension, and equals False if it is not.

Return type:

bool

parse_and_load(arg: str) list[Definition][source]

Convenience function that parses a file or string and loads the definitions into the context.

Parameters:

arg (str) – An AaC definition file. Can be a string in YAML format or a filepath.

Returns:

A list of definition objects which have been loaded into the Language Context.

Return type:

list[Definition]

register_plugin_runner(runner: PluginRunner) None[source]

Register a plugin runner.

Parameters:

runner (PluginRunner) – A plugin runner to be registered.

Return type:

None

remove_definitions(definitions: list[Definition]) None[source]

Remove the given definitions from the context.

Parameters:

definitions (list[Definition]) – A list of Definitions to be removed from the Language Context.

Return type:

None