Source code for gam.ast.base_ast

"""
GAM AST structure.

The main idea is to have a structure that is easy to understand and easy to parse.
- Model holds the data.
    e.g. User, Product, Order, etc.
- Controller handles the business logic.
    e.g. UserController, ProductController, OrderController, etc.
- Repository handles the data access.
    e.g. UserRepository, ProductRepository, OrderRepository, etc.
- View handles the UI.
    e.g. UserView, ProductView, OrderView, etc.
- Event handles the events.
    e.g. UserEvent, ProductEvent, OrderEvent, etc.

Program:
    - modules: List[Module]
        - repository: Repository
            - methods: List[FunctionDeclaration]
        - controller: Controller
            - methods: List[FunctionDeclaration]
        - model: Model
            - structs: List[StructDeclaration]
        - view: View
            - methods: List[FunctionDeclaration]
        - event: Event
            - methods: List[FunctionDeclaration]
    - entry_point: CallExpression (the entry point of the program)
"""


from typing import Optional, Literal

from pydantic import BaseModel, Field, ConfigDict


[docs] class ASTNode(BaseModel): """Base class for all AST nodes""" name: Literal['ASTNode'] = Field(default='ASTNode')
[docs] class Config: arbitrary_types_allowed = True extra = "allow"
[docs] class Expression(ASTNode): """Base class for all expressions""" name: Literal['Expression'] = Field(default='Expression')
[docs] class Statement(ASTNode): """Base class for all statements""" name: Literal['Statement'] = Field(default='Statement')