Building with Codegen
Inheritable Behaviors
Codegen uses a set of core behaviors that can be inherited by code elements. These behaviors provide consistent APIs across different types of symbols.
Core Behaviors
- HasName: For elements with Names (Functions, Classes, Assignments, etc.)
- HasValue: For elements with Values (Arguments, Assignments, etc.)
- HasBlock: For elements containing CodeBlocks (Files, Functions, Classes)
- Editable: For elements that can be safely modified (learn more)
These “behaviors” are implemented as inherited classes.
Working with Names
The HasName behavior provides APIs for working with named elements:
Working with Values
The HasValue behavior provides APIs for elements that have values:
Working with Code Blocks
The HasBlock behavior provides APIs for elements containing code:
Learn more about CodeBlocks and Statements here
Working with Attributes
The get_attribute method provides APIs for attribute access:
Learn more about working with Attributes here.
Behavior Combinations
Many code elements inherit multiple behaviors. For example, a function typically has:
Was this page helpful?