Skip to content

Commit

Permalink
Docs: Provide YAML example to Variant
Browse files Browse the repository at this point in the history
Signed-off-by: Gunnar Andersson <[email protected]>
  • Loading branch information
gunnar-mb committed Jan 9, 2025
1 parent cd1c2f1 commit 8b82cf9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ifex/model/ifex_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,7 @@ class Typedef:
"""
Dataclass used to represent IFEX Typedef.
Each typedef is an alias to an existing fundamental type, defined type, or enumerator, giving it an additional name.
The new data type can be used by other datatypes, method & event parameters, and properties.
A Typedef is an alias to an existing fundamental type or defined type, including structs, enumerators, etc. It can also be used to name and define a variant type. The new data type name can be used in the definition of other datatypes, method- and event-parameters, and properties.
A typedefs list object example is given below:
Expand All @@ -432,10 +431,22 @@ class Typedef:
description: The movement of a seat component
```
Variant types:
**Variant types**
The fields `datatype` and `datatypes` are mutually exclusive - only one of them may have a value. The field `datatypes` is used to specify multiple types associated with this type name. Doing this makes it a `variant` type. It is also possible to define a variant type using the `variant<a,b,c>`-style syntax in any location requiring a datatype, but the ability to specify it as a list can be more useful if the number of types is large. Handling this as a list can also allow Layers to extend a variant type more conveniently.
```yaml
typedefs:
- name: StringOrStruct
datatypes:
- string
- MyStruct
- OtherStruct
description: The Thing, represented in one of 3 ways.
```
**NOTE!** The fields `datatype` and `datatypes` are defined as optional in the language model, but one of them must be defined.
"""

name: str
Expand Down

0 comments on commit 8b82cf9

Please sign in to comment.