Source code for gam.ast.types

from abc import ABC
from typing import List, Literal

from pydantic import Field

from gam.ast.base_ast import ASTNode
from gam.ast.expr import Identifier


[docs] class TypeAnnotation(ASTNode, ABC): """Base class for all type annotations in the AST.""" name: Literal['TypeAnnotation'] = Field(default='TypeAnnotation') type_name: str = Field( description="The name of the type" ) generic_params: List[str] = Field( default_factory=list, description="List of generic type parameters" )
[docs] class StringType(TypeAnnotation): """Represents a string type annotation in the AST.""" name: Literal['StringType'] = Field(default='StringType') type_name: str = Field( default="string", description="The name of the string type" ) generic_params: List[str] = Field( default_factory=list, description="List of generic type parameters" )
[docs] class IntType(TypeAnnotation): """Represents an integer type annotation in the AST.""" name: Literal['IntType'] = Field(default='IntType') type_name: str = Field( default="int", description="The name of the integer type" ) generic_params: List[str] = Field( default_factory=list, description="List of generic type parameters" )
[docs] class BoolType(TypeAnnotation): """Represents a boolean type annotation in the AST.""" name: Literal['BoolType'] = Field(default='BoolType') type_name: str = Field( default="bool", description="The name of the boolean type" ) generic_params: List[str] = Field( default_factory=list, description="List of generic type parameters" )
[docs] class FloatType(TypeAnnotation): """Represents a floating-point type annotation in the AST.""" name: Literal['FloatType'] = Field(default='FloatType') type_name: str = Field( default="float", description="The name of the floating-point type" ) generic_params: List[str] = Field( default_factory=list, description="List of generic type parameters" )
[docs] class NullType(TypeAnnotation): """Represents a null type annotation in the AST.""" name: Literal['NullType'] = Field(default='NullType') type_name: str = Field( default="null", description="The name of the null type" ) generic_params: List[str] = Field( default_factory=list, description="List of generic type parameters" )
[docs] class DateTimeType(TypeAnnotation): """Represents a datetime type annotation in the AST.""" name: Literal['DateTimeType'] = Field(default='DateTimeType') type_name: str = Field( default="datetime", description="The name of the datetime type" ) generic_params: List[str] = Field( default_factory=list, description="List of generic type parameters" )
[docs] class ArrayType(TypeAnnotation): """Represents an array type annotation in the AST.""" name: Literal['ArrayType'] = Field(default='ArrayType') type_name: str = Field( default="array", description="The name of the array type" ) element_type: TypeAnnotation = Field( description="The type of the array elements" ) generic_params: List[str] = Field( default_factory=list, description="List of generic type parameters" )
[docs] class ObjectType(TypeAnnotation): """Represents an object type annotation in the AST.""" name: Literal['ObjectType'] = Field(default='ObjectType') type_name: str = Field( default="object", description="The name of the object type" ) generic_params: List[str] = Field( default_factory=list, description="List of generic type parameters" )
[docs] class StructType(TypeAnnotation): """Represents a struct type annotation in the AST.""" name: Literal['StructType'] = Field(default='StructType') type_name: str = Field( default="struct", description="The name of the struct type" ) struct_type: Identifier = Field( description="The identifier of the struct type" ) generic_params: List[str] = Field( default_factory=list, description="List of generic type parameters" )
[docs] class OptionalType(TypeAnnotation): """Represents an optional type annotation in the AST.""" name: Literal['OptionalType'] = Field(default='OptionalType') type_name: str = Field( default="optional", description="The name of the optional type" ) type_annotation: TypeAnnotation = Field( description="The type of the optional type. It can be any type." ) generic_params: List[str] = Field( default_factory=list, description="List of generic type parameters" )
[docs] class AnyType(TypeAnnotation): """Represents an any type annotation in the AST.""" name: Literal['AnyType'] = Field(default='AnyType') type_name: str = Field( default="any", description="The name of the any type" ) generic_params: List[str] = Field( default_factory=list, description="List of generic type parameters" )