arxlang / astx

https://astx.arxlang.org/
Other
1 stars 4 forks source link

`AwaitExpr`/`AsyncFunction` - Represents an await expression (common in async programming). #108

Open xmnlab opened 1 week ago

xmnlab commented 1 week ago

from gpt:

1. Update ASTKind Enum in astx/base.py

Add the following lines to your ASTKind enumeration to include the new AwaitExprKind and AsyncFunctionDefKind:

@public
class ASTKind(Enum):
    # ... existing kinds ...

    AwaitExprKind = -813  # Add this line
    AsyncFunctionDefKind = -814  # Add this line

2. Define AwaitExpr Class

Add the following class definition to represent the AwaitExpr, likely in astx/expressions.py:

@public
class AwaitExpr(Expr):
    """AST class for await expressions."""

    value: Expr

    def __init__(
        self,
        value: Expr,
        loc: SourceLocation = NO_SOURCE_LOCATION,
        parent: Optional[ASTNodes] = None,
    ) -> None:
        super().__init__(loc=loc, parent=parent)
        self.value = value
        self.kind = ASTKind.AwaitExprKind

Notes:


3. Define AsyncFunctionDef Class

Add the following class definition to represent an asynchronous function definition, possibly in astx/callables.py:

@public
class AsyncFunctionDef(FunctionDef):
    """AST class for asynchronous function definitions."""

    def __init__(
        self,
        name: str,
        args: Arguments,
        body: Block,
        returns: Optional[Expr] = None,
        decorators: Optional[List[Expr]] = None,
        loc: SourceLocation = NO_SOURCE_LOCATION,
        parent: Optional[ASTNodes] = None,
    ) -> None:
        super().__init__(name, args, body, returns, decorators, loc, parent)
        self.kind = ASTKind.AsyncFunctionDefKind

Notes:


Additional Considerations

xmnlab commented 1 week ago

PS: in astx, the name of the class is Function, instead of FunctionDef. maybe it would make sense to rename it to FunctionDef in the future