aac.context.definition_parser¶
Definition Parser class for AaC, contains a load_definition function that handles loading of definition files.
Classes
Definition Parser class, responsible for loading definition files. |
- class aac.context.definition_parser.DefinitionParser[source]¶
Definition Parser class, responsible for loading definition files.
- add_field_to_class(field: dict, instance_class: Type, schema_definition: Definition) Type [source]¶
Creates an attribute within the instance class and adds the field name and type to it.
- Parameters:
field (dict) – The field being loaded into the instance class.
instance_class (Type) – The instance class being loaded with field definitions.
schema_definition (Definition) – The schema definition containing the fields being iterated through and loaded.
- Returns:
the instance class after being loaded with field definitions.
- Return type:
Type
- create_definition_instance(definition: Definition) Any [source]¶
Populates the instance field of a given definition.
- Parameters:
definition (Definition) – The given definition being populated.
- Returns:
The populated instance for the given definition.
- Return type:
Any
- create_enum_class(enum_definition: Definition) Enum [source]¶
Creates an enum class from a given enum definition.
- Parameters:
enum_definition (Definition) – An enum definition to convert to a class.
- Returns:
The created class.
- Return type:
Enum
- create_field_instance(field_name: str, field_type: str, is_required: bool, field_value: Any, lexemes: list[Lexeme]) Any [source]¶
Adds an entry to the instance attribute of a definition for the given field.
- Parameters:
field_name (str) – Name of the field.
field_type (str) – Type of the field.
is_required (bool) – Contents of the is_required field for the specified field.
field_value (Any) – The value for the specified field.
lexemes (list[Lexeme]) – A list of definition Lexemes.
- Returns:
The instance field value.
- Return type:
Any
- create_instance_class(inheritance_parents: list, schema_definition: Definition) Type [source]¶
Method to create an instance class type for the given definition.
- Parameters:
inheritance_parents (list[Type]) – Types that this definition inherits from.
schema_definition (Definition) – The definition being converted to an instance class.
- Returns:
The created instance class.
- Return type:
Type
- create_object_instance(type_class: Type, fields: dict) Any [source]¶
Creates an instance object from the given fields.
- Parameters:
type_class (Type) – The class created from the field type.
fields (dict) – Given fields to create instances from.
- Returns:
The created instance object.
- Return type:
Any
- create_schema_class(schema_definition: Definition) Type [source]¶
Creates a schema class from a given schema definition.
- Parameters:
schema_definition (Definition) – A schema definition to convert to a class.
- Returns:
The created class.
- Return type:
Type
- enum_field_value_check(is_list: bool, field_value: Any, field_name: str, lexemes: list, defining_definition: Definition) list [source]¶
Method used to ensure enum type field definitions have valid values.
- Parameters:
is_list (bool) – Boolean value determining if the field type is a list.
field_value (Any) – Value stored in the field.
field_name (str) – The name of the field.
lexemes (List[Lexeme]) – A list of definition Lexemes.
defining_definition (Definition) – Definition containing the field being checked.
- Returns:
The list of valid enum field values.
- Return type:
list
- field_instance_check(is_list: bool, field_value: Any, field_name: str, is_required: bool, lexemes: list[Lexeme], defining_definition: Definition, instance_class: Type) list [source]¶
Method used to check if a field is a list, and to call the corresponding field instance creator method.
- Parameters:
is_list (bool) – Boolean value determining if the field type is a list.
field_value (Any) – Value stored in the field.
field_name (str) – The name of the field.
lexemes (List[Lexeme]) – A list of definition Lexemes.
defining_definition (Definition) – Definition containing the field being checked.
instance_class (Type) – The class type of the instance being created.
is_required (bool)
- Returns:
The created instance list.
- Return type:
list
- field_instance_creator_list(lexemes: list, field_value: Any, field_name: str, defining_definition: Definition, instance: list, instance_class: Type) list [source]¶
Method to create instance fields from list type fields.
- Parameters:
lexemes (List[Lexeme]) – A list of definition Lexemes.
field_value (Any) – Value stored in the field.
field_name (str) – The name of the field.
defining_definition (Definition) – Definition containing the field being checked.
(list[Any] (instance) – The instance that will contain the created field)
instance_class (Type) – The instance type class
instance (list)
- Returns:
The updated instance containing the created field.
- Return type:
list
- field_instance_creator_not_list(lexemes: list, field_value: Any, field_name: str, defining_definition: Definition, instance: list, instance_class: Type) list [source]¶
Method to create instance fields from non-list type fields.
- Parameters:
lexemes (List[Lexeme]) – A list of definition Lexemes.
field_value (Any) – Value stored in the field.
field_name (str) – The name of the field.
defining_definition (Definition) – Definition containing the field being checked.
(list[Any] (instance) – The instance that will contain the created field)
instance_class (Type) – The instance type class
instance (list)
- Returns:
The updated instance containing the created field
- Return type:
list
- find_definitions_by_name(name: str) list[Definition] [source]¶
Method to find a definition by name.
- Parameters:
name (str) – The name of the definition being searched for.
- Returns:
The definition with the given name.
- Return type:
list[Definition]
- get_defined_fields(package: str, name: str) list[str] [source]¶
Returns a list of defined fields for the given definition.
- Parameters:
package (str) – The definition package.
name (str) – The definition name.
- Returns:
A list of definition fields.
- Return type:
list[str]
- get_inheritance_parents(definition: Definition) list[Type] [source]¶
Looks up the inheritance parent classes for the given definition and returns them as a list of Python classes.
- Parameters:
definition (Definition) – The definition whose parent class(es) is being searched for.
- Returns:
The parent class(es) as a list of Python classes.
- Return type:
list[Type]
- get_location_str(lexeme_value: str, lexemes: list[Lexeme]) str [source]¶
Method to find the file name and line number for a requested Lexeme value.
- Parameters:
lexeme_value (str) – The Lexeme to match.
lexemes (list[Lexeme]) – A list of definition Lexemes.
- Returns:
The file name and line number of the requested Lexeme value.
- Return type:
str
- load_definitions(context, parsed_definitions: list[Definition]) list[Definition] [source]¶
Loads the given definitions into the context and populates the instance with a python object.
- Parameters:
context (LanguageContext) – An instance of the active LanguageContext.
parsed_definitions (list[Definition]) – (list[Definition]): The parsed contents of a definition file.
- Returns:
The parsed definitions to load into the LanguageContext.
- Return type:
list[Definition]
- populate_sub_fields(subfields: dict, defining_definition: Definition, item: dict, lexemes: list[Lexeme]) dict [source]¶
Method used to populate sub-fields in an instance class field.
- Parameters:
subfields (dict) – dictionary containing relevant sub-fields.
defining_definition (Definition) – The overall definition containing the field.
item (dict) – The current field definition which contains sub-fields.
lexemes (List[Lexeme]) – A list of definition Lexemes.
- Returns:
The populated dictionary of sub-fields.
- Return type:
dict
- primitive_field_value_check(is_list: bool, field_value: Any, field_name: str, is_required: bool, lexemes: list, defining_definition: Definition) Any [source]¶
Method used to ensure primitive type field definitions have valid values.
- Parameters:
is_list (bool) – Boolean value determining if the field type is a list.
field_value (Any) – Value stored in the field.
field_name (str) – The name of the field.
is_required (bool) – Boolean value determining if the field is required.
lexemes (List[Lexeme]) – A list of definition Lexemes.
defining_definition (Definition) – Definition containing the field being checked.
- Returns:
The content of the primitive type field value.
- Return type:
Any
- schema_field_value_check(is_list, field_value, field_name: str, is_required, lexemes, defining_definition) list [source]¶
Method used to ensure schema type field definitions have valid values.
- Parameters:
is_list (bool) – Boolean value determining if the field type is a list.
field_value (Any) – Value stored in the field.
field_name (str) – The name of the field.
lexemes (List[Lexeme]) – A list of definition Lexemes.
defining_definition (Definition) – Definition containing the field being checked.
- Returns:
The List of valid schema defined field values.
- Return type:
list