Skip to content

astx

ASTx.

Modules:

  • base

    AST classes and functions.

  • blocks

    Module for different kind of ASTx blocks.

  • callables

    Module for callable ASTx.

  • classes

    Module for classes definitions/declarations.

  • flows

    Module for controle flow AST.

  • literals

    AST nodes for literals.

  • mixes

    Module for mixing ASTx types from different modules.

  • modifiers

    Modifications for ASTx, such as visibility, scope, etc.

  • packages

    Define ASTx for more broader scope.

  • symbol_table

    Symbol Table module for ASTx.

  • tools

    Package for astx helper tools.

  • types

    Collection of ASTx nodes used for types.

  • variables

    Module for Variables.

  • viz

    AST graphic representation Module.

Classes:

Functions:

AST

AST(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

AST main expression class.

Methods:

  • get_struct

    Return a structure that represents the node object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
180
181
182
183
184
185
186
187
188
189
190
191
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the AST instance."""
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct abstractmethod

get_struct(simplified: bool = False) -> ReprStruct

Return a structure that represents the node object.

Source code in src/astx/base.py
255
256
257
@abstractmethod
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a structure that represents the node object."""

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ASTKind

Bases: Enum

The expression kind class used for downcasting.

AliasExpr

AliasExpr(name: str, asname: str = '', loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

Represents an alias in an import statement.

Methods:

  • get_struct

    Return the AST structure of the alias.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/packages.py
167
168
169
170
171
172
173
174
175
176
177
def __init__(
    self,
    name: str,
    asname: str = "",
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.name = name
    self.asname = asname
    self.kind = ASTKind.AliasExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the alias.

Source code in src/astx/packages.py
186
187
188
189
190
191
192
193
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the alias."""
    str_asname = f", {self.asname}" if self.asname else ""
    str_name_asname = f"[{self.name}{str_asname}]"
    key = f"Alias {str_name_asname}"
    value = ""

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Argument

Argument(name: str, type_: DataType, mutability: MutabilityKind = constant, default: Expr = UNDEFINED, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Variable

AST class for argument definition.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/callables.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def __init__(
    self,
    name: str,
    type_: DataType,
    mutability: MutabilityKind = MutabilityKind.constant,
    default: Expr = UNDEFINED,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the VarExprAST instance."""
    super().__init__(name=name, loc=loc, parent=parent)
    self.mutability = mutability
    self.type_ = type_
    self.default = default
    self.kind = ASTKind.ArgumentKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/callables.py
60
61
62
63
64
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    key = f"Argument[{self.name}, {self.type_}] = {self.default}"
    value = self.default.get_struct()
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Arguments

Arguments(*args: Argument, **kwargs: Any)

Bases: ASTNodes[Argument]

AST class for argument definition.

Methods:

  • append

    Append a new node to the stack.

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/callables.py
72
73
74
75
def __init__(self, *args: Argument, **kwargs: Any) -> None:
    super().__init__(**kwargs)
    for arg in args:
        self.append(arg)

append

append(value: ASTType) -> None

Append a new node to the stack.

Source code in src/astx/base.py
305
306
307
def append(self, value: ASTType) -> None:
    """Append a new node to the stack."""
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/callables.py
81
82
83
84
85
86
87
88
89
90
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    args_nodes = []

    for node in self.nodes:
        args_nodes.append(node.get_struct(simplified))

    key = str(self)
    value = cast(ReprStruct, args_nodes)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

BinaryOp

BinaryOp(op_code: str, lhs: DataType, rhs: DataType, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: DataTypeOps

AST class for the binary operator.

Methods:

  • get_struct

    Return the AST structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/types/operators.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def __init__(
    self,
    op_code: str,
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize the BinaryOp instance."""
    super().__init__()

    self.loc = loc
    self.op_code = op_code
    self.lhs = lhs
    self.rhs = rhs
    self.kind = ASTKind.BinaryOpKind

    if not (
        isinstance(lhs.type_, DataType) and isinstance(rhs.type_, DataType)
    ):
        raise Exception(
            "For now, binary operators are just allowed for `DataType`."
            f"LHS: {lhs.type_}, RHS: {rhs.type_}"
        )

    if lhs.type_ == rhs.type_:
        self.type_ = lhs.type_
    else:
        # type inference
        self.type_ = max([lhs.type_, rhs.type_], key=lambda v: v.nbytes)

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure that represents the object.

Source code in src/astx/types/operators.py
158
159
160
161
162
163
164
165
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure that represents the object."""
    key = f"BINARY[{self.op_code}]"
    lhs = {"lhs": self.lhs.get_struct(simplified)}
    rhs = {"rhs": self.rhs.get_struct(simplified)}

    content: ReprStruct = {**lhs, **rhs}
    return self._prepare_struct(key, content, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Block

Block(name: str = 'entry', loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: ASTNodes[ASTType]

The AST tree.

Methods:

  • append

    Append a new node to the stack.

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
278
279
280
281
282
283
284
285
286
287
288
def __init__(
    self,
    name: str = "entry",
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the AST instance."""
    super().__init__(loc=loc, parent=parent)
    self.name = name
    self.nodes: list[ASTType] = []
    self.position: int = 0

append

append(value: ASTType) -> None

Append a new node to the stack.

Source code in src/astx/base.py
305
306
307
def append(self, value: ASTType) -> None:
    """Append a new node to the stack."""
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/blocks.py
22
23
24
25
26
27
28
29
30
31
32
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    block_nodes = []

    for node in self.nodes:
        block_nodes.append(node.get_struct(simplified))

    key = f"BLOCK[{self.name}]"
    value = cast(ReprStruct, block_nodes)

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Boolean

Boolean(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: AnyType

Boolean data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ClassDeclStmt

ClassDeclStmt(name: str, bases: Iterable[Expr] | ASTNodes = [], decorators: Iterable[Expr] | ASTNodes = [], visibility: VisibilityKind = public, is_abstract: bool = False, metaclass: Optional[Expr] = None, attributes: Iterable[VariableDeclaration] | ASTNodes = [], methods: Iterable[Function] | ASTNodes = [], loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for class declaration.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/classes.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def __init__(
    self,
    name: str,
    bases: Iterable[Expr] | ASTNodes = [],
    decorators: Iterable[Expr] | ASTNodes = [],
    visibility: VisibilityKind = VisibilityKind.public,
    is_abstract: bool = False,
    metaclass: Optional[Expr] = None,
    attributes: Iterable[VariableDeclaration] | ASTNodes = [],
    methods: Iterable[Function] | ASTNodes = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize ClassDeclStmt instance."""
    super().__init__(loc=loc, parent=parent)
    self.name = name

    if isinstance(bases, ASTNodes):
        self.bases = bases
    else:
        self.bases = ASTNodes()
        for base in bases:
            self.bases.append(base)

    if isinstance(decorators, ASTNodes):
        self.decorators = decorators
    else:
        self.decorators = ASTNodes()
        for decorator in decorators:
            self.decorators.append(decorator)

    self.attributes = ASTNodes()
    for a in attributes:
        self.attributes.append(a)

    self.methods = ASTNodes()
    for m in methods:
        self.methods.append(m)

    self.visibility = visibility
    self.is_abstract = is_abstract
    self.metaclass = metaclass
    self.kind = ASTKind.ClassDeclStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/classes.py
144
145
146
147
148
149
150
151
152
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    vis = dict(zip(("public", "private", "protected"), ("+", "-", "#")))
    abstract = ", abstract" if self.is_abstract else ""

    key = f"CLASS-DECL[{vis[self.visibility.name]}{self.name}{abstract}]"
    value = self._get_struct_wrapper(simplified)

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ClassDefStmt

ClassDefStmt(name: str, bases: Iterable[Expr] | ASTNodes = [], decorators: Iterable[Expr] | ASTNodes = [], body: Block = CLASS_BODY_DEFAULT, visibility: VisibilityKind = public, is_abstract: bool = False, metaclass: Optional[Expr] = None, attributes: Iterable[VariableDeclaration] | ASTNodes = [], methods: Iterable[Function] | ASTNodes = [], loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: ClassDeclStmt

AST class for class definition, including attributes and methods.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/classes.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
def __init__(
    self,
    name: str,
    bases: Iterable[Expr] | ASTNodes = [],
    decorators: Iterable[Expr] | ASTNodes = [],
    body: Block = CLASS_BODY_DEFAULT,
    visibility: VisibilityKind = VisibilityKind.public,
    is_abstract: bool = False,
    metaclass: Optional[Expr] = None,
    attributes: Iterable[VariableDeclaration] | ASTNodes = [],
    methods: Iterable[Function] | ASTNodes = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize ClassDefStmt instance."""
    super().__init__(
        name=name,
        bases=bases,
        decorators=decorators,
        visibility=visibility,
        is_abstract=is_abstract,
        metaclass=metaclass,
        attributes=attributes,
        methods=methods,
        loc=loc,
        parent=parent,
    )

    if body != CLASS_BODY_DEFAULT:
        self.body = body
    else:
        self.body = copy.deepcopy(body)
        self.body.name = f"{name}_body"
    self.kind = ASTKind.ClassDefStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/classes.py
209
210
211
212
213
214
215
216
217
218
219
220
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    vis = dict(zip(("public", "private", "protected"), ("+", "-", "#")))
    abstract = ", abstract" if self.is_abstract else ""

    key = f"CLASS-DEF[{vis[self.visibility.name]}{self.name}{abstract}]"
    value = self._get_struct_wrapper(simplified)

    if self.body != CLASS_BODY_DEFAULT:
        value["body"] = self.body.get_struct(simplified)

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Complex

Complex(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Number

Base class for complex numbers.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Complex32

Complex32(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Complex

Complex32 data type class.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Complex64

Complex64(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Complex

Complex64 data type class.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

DataType

DataType(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: ExprType

AST main expression class.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

DataTypeOps

DataTypeOps(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: DataType

Overload some magic functions used for the main operations.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Date

Date(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Temporal

Date data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

DateTime

DateTime(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Temporal

DateTime data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Expr

Expr(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: AST

AST main expression class.

Methods:

  • get_struct

    Return a structure that represents the node object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
180
181
182
183
184
185
186
187
188
189
190
191
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the AST instance."""
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct abstractmethod

get_struct(simplified: bool = False) -> ReprStruct

Return a structure that represents the node object.

Source code in src/astx/base.py
255
256
257
@abstractmethod
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a structure that represents the node object."""

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ExprType

ExprType(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

ExprType expression class.

Methods:

  • get_struct

    Return a structure that represents the node object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
180
181
182
183
184
185
186
187
188
189
190
191
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the AST instance."""
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a structure that represents the node object.

Source code in src/astx/base.py
344
345
346
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a structure that represents the node object."""
    return {"Type": self.__class__.__name__}

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Float16

Float16(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Floating

Float16 data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Float32

Float32(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Floating

Float32 data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Float64

Float64(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Floating

Float64 data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Floating

Floating(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Number

AST for the literal float number.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ForCountLoopExpr

ForCountLoopExpr(initializer: InlineVariableDeclaration, condition: Expr, update: Expr, body: Block, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

AST class for a simple Count-Controlled For Loop expression.

This is a very basic for loop, used by languages like C or C++.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/flows.py
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
def __init__(
    self,
    initializer: InlineVariableDeclaration,
    condition: Expr,
    update: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the ForLoopCountExpr instance."""
    super().__init__(loc=loc, parent=parent)
    self.initializer = initializer
    self.condition = condition
    self.update = update
    self.body = body
    self.kind = ASTKind.ForCountLoopExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/flows.py
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    for_init = {"initialization": self.initializer.get_struct(simplified)}
    for_cond = {"condition": self.condition.get_struct(simplified)}
    for_update = {"update": self.update.get_struct(simplified)}
    for_body = self.body.get_struct(simplified)

    key = "FOR-COUNT-EXPR"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, for_init),
        **cast(DictDataTypesStruct, for_cond),
        **cast(DictDataTypesStruct, for_update),
        **cast(DictDataTypesStruct, for_body),
    }
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ForCountLoopStmt

ForCountLoopStmt(initializer: InlineVariableDeclaration, condition: Expr, update: Expr, body: Block, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for a simple Count-Controlled For Loop statement.

This is a very basic for loop, used by languages like C or C++.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/flows.py
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
def __init__(
    self,
    initializer: InlineVariableDeclaration,
    condition: Expr,
    update: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the ForCountLoopStmt instance."""
    super().__init__(loc=loc, parent=parent)
    self.initializer = initializer
    self.condition = condition
    self.update = update
    self.body = body
    self.kind = ASTKind.ForCountLoopStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/flows.py
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    for_init = {"initialization": self.initializer.get_struct(simplified)}
    for_cond = {"condition": self.condition.get_struct(simplified)}
    for_update = {"update": self.update.get_struct(simplified)}
    for_body = self.body.get_struct(simplified)

    key = "FOR-COUNT-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, for_init),
        **cast(DictDataTypesStruct, for_cond),
        **cast(DictDataTypesStruct, for_update),
        **cast(DictDataTypesStruct, for_body),
    }

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ForRangeLoopExpr

ForRangeLoopExpr(variable: InlineVariableDeclaration, start: Expr, end: Expr, step: Expr, body: Block, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

AST class for For Range Expression.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/flows.py
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
def __init__(
    self,
    variable: InlineVariableDeclaration,
    start: Expr,
    end: Expr,
    step: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the ForRangeLoopExpr instance."""
    super().__init__(loc=loc, parent=parent)
    self.variable = variable
    self.start = start
    self.end = end
    self.step = step
    self.body = body
    self.kind = ASTKind.ForRangeLoopExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/flows.py
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    for_var = {"var": self.variable.get_struct(simplified)}
    for_start = {"start": self.start.get_struct(simplified)}
    for_end = {"end": self.end.get_struct(simplified)}
    for_step = {"step": self.step.get_struct(simplified)}
    for_body = self.body.get_struct(simplified)

    key = "FOR-RANGE-LOOP-EXPR"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, for_var),
        **cast(DictDataTypesStruct, for_start),
        **cast(DictDataTypesStruct, for_end),
        **cast(DictDataTypesStruct, for_step),
        **cast(DictDataTypesStruct, for_body),
    }
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ForRangeLoopStmt

ForRangeLoopStmt(variable: InlineVariableDeclaration, start: Expr, end: Expr, step: Expr, body: Block, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for For Range Statement.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/flows.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
def __init__(
    self,
    variable: InlineVariableDeclaration,
    start: Expr,
    end: Expr,
    step: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the ForRangeLoopStmt instance."""
    super().__init__(loc=loc, parent=parent)
    self.variable = variable
    self.start = start
    self.end = end
    self.step = step
    self.body = body
    self.kind = ASTKind.ForRangeLoopStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/flows.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    for_start = {"start": self.start.get_struct(simplified)}
    for_end = {"end": self.end.get_struct(simplified)}
    for_step = {"step": self.step.get_struct(simplified)}
    for_body = self.body.get_struct(simplified)

    key = "FOR-RANGE-LOOP-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, for_start),
        **cast(DictDataTypesStruct, for_end),
        **cast(DictDataTypesStruct, for_step),
        **cast(DictDataTypesStruct, for_body),
    }
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Function

Function(prototype: FunctionPrototype, body: Block, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for function definition.

Methods:

  • get_struct

    Get the AST structure that represent the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Attributes:

  • name (str) –

    Return the function prototype name.

Source code in src/astx/callables.py
216
217
218
219
220
221
222
223
224
225
226
227
def __init__(
    self,
    prototype: FunctionPrototype,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the Function instance."""
    super().__init__(loc=loc, parent=parent)
    self.prototype = prototype
    self.body = body
    self.kind = ASTKind.FunctionKind

name property

name: str

Return the function prototype name.

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Get the AST structure that represent the object.

Source code in src/astx/callables.py
247
248
249
250
251
252
253
254
255
256
257
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Get the AST structure that represent the object."""
    fn_args = self.prototype.args.get_struct(simplified)
    fn_body = self.body.get_struct(simplified)

    key = f"FUNCTION[{self.prototype.name}]"
    args_struct = {"args": fn_args}
    body_struct = {"body": fn_body}

    value: ReprStruct = {**args_struct, **body_struct}
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

FunctionCall

FunctionCall(fn: Function, args: Iterable[DataType], type_: DataType = AnyType(), loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: DataType

AST class for function call.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/callables.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def __init__(
    self,
    fn: Function,
    args: Iterable[DataType],
    type_: DataType = AnyType(),
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the Call instance."""
    super().__init__(loc=loc, parent=parent)
    self.fn = fn
    self.args = args
    self.kind = ASTKind.CallKind
    self.type_ = type_

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/callables.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    call_params = []

    for node in self.args:
        call_params.append(node.get_struct(simplified))

    key = f"FUNCTION-CALL[{self.fn.name}]"
    value = cast(
        ReprStruct,
        {
            f"Parameters ({len(call_params)})": {
                f"param({idx})": param
                for idx, param in enumerate(call_params)
            }
        },
    )

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

FunctionPrototype

FunctionPrototype(name: str, args: Arguments, return_type: AnyType, scope: ScopeKind = global_, visibility: VisibilityKind = public, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for function prototype declaration.

Methods:

  • get_struct

    Get the AST structure that represent the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/callables.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def __init__(
    self,
    name: str,
    args: Arguments,
    return_type: AnyType,
    scope: ScopeKind = ScopeKind.global_,
    visibility: VisibilityKind = VisibilityKind.public,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the FunctionPrototype instance."""
    super().__init__(loc=loc, parent=parent)
    self.name = name
    self.args = args
    self.return_type = return_type
    self.loc = loc
    self.kind = ASTKind.PrototypeKind
    self.scope = scope
    self.visibility = visibility

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Get the AST structure that represent the object.

Source code in src/astx/callables.py
174
175
176
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Get the AST structure that represent the object."""
    raise Exception("Visitor method not necessary")

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

FunctionReturn

FunctionReturn(value: DataType, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for function return statement.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/callables.py
186
187
188
189
190
191
192
193
194
195
def __init__(
    self,
    value: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the Return instance."""
    super().__init__(loc=loc, parent=parent)
    self.value = value
    self.kind = ASTKind.ReturnKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/callables.py
201
202
203
204
205
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    key = "RETURN"
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

IfExpr

IfExpr(condition: Expr, then: Block, else_: Optional[Block] = None, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

AST class for if expression.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/flows.py
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def __init__(
    self,
    condition: Expr,
    then: Block,
    else_: Optional[Block] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the IfExpr instance."""
    super().__init__(loc=loc, parent=parent)
    self.loc = loc
    self.condition = condition
    self.then = then
    self.else_ = else_
    self.kind = ASTKind.IfExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/flows.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    if_condition = {"condition": self.condition.get_struct(simplified)}
    if_then = {"then-block": self.then.get_struct(simplified)}
    if_else: ReprStruct = {}

    if self.else_ is not None:
        if_else = {"else-block": self.else_.get_struct(simplified)}

    key = "IF-EXPR"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, if_condition),
        **cast(DictDataTypesStruct, if_then),
        **cast(DictDataTypesStruct, if_else),
    }

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

IfStmt

IfStmt(condition: Expr, then: Block, else_: Optional[Block] = None, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for if statement.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/flows.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def __init__(
    self,
    condition: Expr,
    then: Block,
    else_: Optional[Block] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the IfStmt instance."""
    super().__init__(loc=loc, parent=parent)
    self.loc = loc
    self.condition = condition
    self.then = then
    self.else_ = else_
    self.kind = ASTKind.IfStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/flows.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    if_condition = {"condition": self.condition.get_struct(simplified)}
    if_then = {"then-block": self.then.get_struct(simplified)}
    if_else: ReprStruct = {}

    if self.else_ is not None:
        if_else = {"else-block": self.else_.get_struct(simplified)}

    key = "IF-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, if_condition),
        **cast(DictDataTypesStruct, if_then),
        **cast(DictDataTypesStruct, if_else),
    }

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ImportExpr

ImportExpr(names: list[AliasExpr], loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

Represents an import operation as an expression.

Methods:

  • get_struct

    Return the AST structure of the import expression.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/packages.py
281
282
283
284
285
286
287
288
289
def __init__(
    self,
    names: list[AliasExpr],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.names = names
    self.kind = ASTKind.ImportExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the import expression.

Source code in src/astx/packages.py
296
297
298
299
300
301
302
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the import expression."""
    key = "ImportExpr"
    value = cast(
        ReprStruct, [name.get_struct(simplified) for name in self.names]
    )
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ImportFromExpr

ImportFromExpr(names: list[AliasExpr], module: str = '', level: int = 0, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

Represents a 'from ... import ...' operation as an expression.

Methods:

  • get_struct

    Return the AST structure of the import-from expression.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/packages.py
314
315
316
317
318
319
320
321
322
323
324
325
326
def __init__(
    self,
    names: list[AliasExpr],
    module: str = "",
    level: int = 0,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.names = names
    self.module = module
    self.level = level
    self.kind = ASTKind.ImportFromExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the import-from expression.

Source code in src/astx/packages.py
338
339
340
341
342
343
344
345
346
347
348
349
350
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the import-from expression."""
    level_dots = "." * self.level
    module_str = (
        f"{level_dots}{self.module}" if self.module else level_dots
    )

    key = f"ImportFromExpr [{module_str}]"
    value = cast(
        ReprStruct, [name.get_struct(simplified) for name in self.names]
    )

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ImportFromStmt

ImportFromStmt(names: list[AliasExpr], module: str = '', level: int = 0, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

Represents an import-from statement.

Methods:

  • get_struct

    Return the AST structure of the import-from statement.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/packages.py
236
237
238
239
240
241
242
243
244
245
246
247
248
def __init__(
    self,
    names: list[AliasExpr],
    module: str = "",
    level: int = 0,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.module = module
    self.names = names
    self.level = level
    self.kind = ASTKind.ImportFromStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the import-from statement.

Source code in src/astx/packages.py
259
260
261
262
263
264
265
266
267
268
269
270
271
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the import-from statement."""
    level_dots = "." * self.level
    module_str = (
        f"{level_dots}{self.module}" if self.module else level_dots
    )

    key = f"ImportFromStmt [{module_str}]"
    value = cast(
        ReprStruct, [name.get_struct(simplified) for name in self.names]
    )

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ImportStmt

ImportStmt(names: list[AliasExpr], loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

Represents an import statement.

Methods:

  • get_struct

    Return the AST structure of the import statement.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/packages.py
203
204
205
206
207
208
209
210
211
def __init__(
    self,
    names: list[AliasExpr],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.names = names
    self.kind = ASTKind.ImportStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the import statement.

Source code in src/astx/packages.py
218
219
220
221
222
223
224
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the import statement."""
    key = "ImportStmt"
    value = cast(
        ReprStruct, [name.get_struct(simplified) for name in self.names]
    )
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

InlineVariableDeclaration

InlineVariableDeclaration(name: str, type_: DataType, mutability: MutabilityKind = constant, visibility: VisibilityKind = public, scope: ScopeKind = local, value: Expr = UNDEFINED, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

AST class for inline variable declaration expression.

Can be used in expressions like for loops.

Methods:

  • get_struct

    Return a string that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/variables.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
def __init__(
    self,
    name: str,
    type_: DataType,
    mutability: MutabilityKind = MutabilityKind.constant,
    visibility: VisibilityKind = VisibilityKind.public,
    scope: ScopeKind = ScopeKind.local,
    value: Expr = UNDEFINED,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the VarExprAST instance."""
    super().__init__(loc=loc, parent=parent)
    self.mutability = mutability
    self.scope = scope
    self.visibility = visibility
    self.name = name
    self.type_ = type_
    self.value = value
    self.kind = ASTKind.VarDeclKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a string that represents the object.

Source code in src/astx/variables.py
113
114
115
116
117
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a string that represents the object."""
    key = str(self)
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Int16

Int16(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: SignedInteger

Int16 data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Int32

Int32(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: SignedInteger

Int32 data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Int64

Int64(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: SignedInteger

Int64 data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Int8

Int8(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: SignedInteger

Int8 data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Integer

Integer(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: AnyType

Integer number data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LambdaExpr

LambdaExpr(body: Expr, params: Arguments = Arguments(), loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

AST class for lambda expressions.

Methods:

  • get_struct

    Return the AST structure of the lambda expression.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/callables.py
268
269
270
271
272
273
274
275
276
277
278
def __init__(
    self,
    body: Expr,
    params: Arguments = Arguments(),
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.params = params
    self.body = body
    self.kind = ASTKind.LambdaExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the lambda expression.

Source code in src/astx/callables.py
285
286
287
288
289
290
291
292
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the lambda expression."""
    key = "LambdaExpr"
    value: ReprStruct = {
        "params": self.params.get_struct(simplified),
        "body": self.body.get_struct(simplified),
    }
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Literal

Literal(*args, **kwargs)

Bases: DataTypeOps

Literal Data type.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/base.py
28
29
30
def __init__(self, *args, **kwargs) -> None:  # type: ignore
    super().__init__(*args, **kwargs)
    self.ref = uuid4().hex

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralBoolean

LiteralBoolean(value: bool, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralBoolean data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/boolean.py
23
24
25
26
27
28
29
30
def __init__(
    self, value: bool, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralBoolean."""
    super().__init__(loc)
    self.value = value
    self.type_ = Boolean()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralComplex

LiteralComplex(real: float, imag: float, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

Base class for literal complex numbers.

Methods:

  • get_struct

    Return the AST representation for the complex literal.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
263
264
265
266
267
268
269
270
271
def __init__(
    self,
    real: float,
    imag: float,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize a generic complex number."""
    super().__init__(loc)
    self.value = real, imag

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the complex literal.

Source code in src/astx/literals/numeric.py
277
278
279
280
281
282
283
284
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the complex literal."""
    key = f"{self.__class__.__name__}: {self.value}"
    value: ReprStruct = {
        "real": self.value[0],
        "imag": self.value[1],
    }
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralComplex32

LiteralComplex32(real: float, imag: float, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: LiteralComplex

LiteralComplex32 data type class.

Methods:

  • get_struct

    Return the AST representation for the complex literal.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
292
293
294
295
296
297
298
299
300
def __init__(
    self,
    real: float,
    imag: float,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize LiteralComplex32."""
    super().__init__(real, imag, loc)
    self.type_ = Complex32()

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the complex literal.

Source code in src/astx/literals/numeric.py
277
278
279
280
281
282
283
284
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the complex literal."""
    key = f"{self.__class__.__name__}: {self.value}"
    value: ReprStruct = {
        "real": self.value[0],
        "imag": self.value[1],
    }
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralComplex64

LiteralComplex64(real: float, imag: float, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: LiteralComplex

LiteralComplex64 data type class.

Methods:

  • get_struct

    Return the AST representation for the complex literal.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
308
309
310
311
312
313
314
315
316
def __init__(
    self,
    real: float,
    imag: float,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize LiteralComplex64."""
    super().__init__(real, imag, loc)
    self.type_ = Complex64()

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the complex literal.

Source code in src/astx/literals/numeric.py
277
278
279
280
281
282
283
284
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the complex literal."""
    key = f"{self.__class__.__name__}: {self.value}"
    value: ReprStruct = {
        "real": self.value[0],
        "imag": self.value[1],
    }
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralDate

LiteralDate(value: str, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralDate data type class.

Methods:

  • get_struct

    Return the structure of the LiteralDate object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/temporal.py
27
28
29
30
31
32
33
34
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralDate."""
    super().__init__(loc)
    self.value = value
    self.type_ = Date()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the structure of the LiteralDate object.

Source code in src/astx/literals/temporal.py
40
41
42
43
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the structure of the LiteralDate object."""
    key = f"LiteralDate: {self.value}"
    return self._prepare_struct(key, self.value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralDateTime

LiteralDateTime(value: str, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralDateTime data type class.

Methods:

  • get_struct

    Return the structure of the LiteralDateTime object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/temporal.py
 99
100
101
102
103
104
105
106
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralDateTime."""
    super().__init__(loc)
    self.value = value
    self.type_ = DateTime()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the structure of the LiteralDateTime object.

Source code in src/astx/literals/temporal.py
112
113
114
115
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the structure of the LiteralDateTime object."""
    key = f"LiteralDateTime: {self.value}"
    return self._prepare_struct(key, self.value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralFloat16

LiteralFloat16(value: float, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralFloat16 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
211
212
213
214
215
216
217
218
def __init__(
    self, value: float, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralFloat16."""
    super().__init__(loc)
    self.value = value
    self.type_ = Float16()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralFloat32

LiteralFloat32(value: float, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralFloat32 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
228
229
230
231
232
233
234
235
def __init__(
    self, value: float, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralFloat32."""
    super().__init__(loc)
    self.value = value
    self.type_ = Float32()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralFloat64

LiteralFloat64(value: float, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralFloat64 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
245
246
247
248
249
250
251
252
def __init__(
    self, value: float, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralFloat64."""
    super().__init__(loc)
    self.value = value
    self.type_ = Float64()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt128

LiteralInt128(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralInt128 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
109
110
111
112
113
114
115
116
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt128."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int128()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt16

LiteralInt16(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralInt16 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
58
59
60
61
62
63
64
65
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt16."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int16()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt32

LiteralInt32(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralInt32 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
75
76
77
78
79
80
81
82
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt32."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int32()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt64

LiteralInt64(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralInt64 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
92
93
94
95
96
97
98
99
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt64."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int64()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt8

LiteralInt8(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralInt8 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
41
42
43
44
45
46
47
48
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt8."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int8()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralTime

LiteralTime(value: str, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralTime data type class.

Methods:

  • get_struct

    Return the structure of the LiteralTime object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/temporal.py
51
52
53
54
55
56
57
58
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralTime."""
    super().__init__(loc)
    self.value = value
    self.type_ = Time()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the structure of the LiteralTime object.

Source code in src/astx/literals/temporal.py
64
65
66
67
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the structure of the LiteralTime object."""
    key = f"LiteralTime: {self.value}"
    return self._prepare_struct(key, self.value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralTimestamp

LiteralTimestamp(value: str, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralTimestamp data type class.

Methods:

  • get_struct

    Return the structure of the LiteralTimestamp object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/temporal.py
75
76
77
78
79
80
81
82
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralTimestamp."""
    super().__init__(loc)
    self.value = value
    self.type_ = Timestamp()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the structure of the LiteralTimestamp object.

Source code in src/astx/literals/temporal.py
88
89
90
91
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the structure of the LiteralTimestamp object."""
    key = f"LiteralTimestamp: {self.value}"
    return self._prepare_struct(key, self.value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt128

LiteralUInt128(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralUInt128 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
194
195
196
197
198
199
200
201
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt128."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt128()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt16

LiteralUInt16(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralUInt16 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
143
144
145
146
147
148
149
150
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt16."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt16()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt32

LiteralUInt32(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralUInt32 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
160
161
162
163
164
165
166
167
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt32."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt32()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt64

LiteralUInt64(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralUInt64 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
177
178
179
180
181
182
183
184
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt64."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt64()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt8

LiteralUInt8(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralUInt8 data type class.

Methods:

  • get_struct

    Return the AST representation for the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/numeric.py
126
127
128
129
130
131
132
133
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt8."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt8()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/literals/base.py
37
38
39
40
41
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUTF8Char

LiteralUTF8Char(value: str, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

Literal class for UTF-8 characters.

Methods:

  • get_struct

    Return the structure of the object in a simplified.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/string.py
50
51
52
53
54
55
56
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    super().__init__(loc)
    self.value = value
    self.type_ = UTF8Char()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the structure of the object in a simplified.

Source code in src/astx/literals/string.py
62
63
64
65
66
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the structure of the object in a simplified."""
    key = f"LiteralUTF8Char: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUTF8String

LiteralUTF8String(value: str, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

Literal class for UTF-8 strings.

Methods:

  • get_struct

    Return the structure of the object in a simplified.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/literals/string.py
24
25
26
27
28
29
30
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    super().__init__(loc)
    self.value = value
    self.type_ = UTF8String()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the structure of the object in a simplified.

Source code in src/astx/literals/string.py
36
37
38
39
40
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the structure of the object in a simplified."""
    key = f"LiteralUTF8String: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Module

Module(name: str = 'main', loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Block

AST main expression class.

Methods:

  • append

    Append a new node to the stack.

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Attributes:

Source code in src/astx/packages.py
53
54
55
56
57
58
59
60
def __init__(
    self,
    name: str = "main",
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize the AST instance."""
    super().__init__(name=name, loc=loc)
    self.kind = ASTKind.ModuleKind

block property

block: list[AST]

Define an alias for self.nodes.

append

append(value: ASTType) -> None

Append a new node to the stack.

Source code in src/astx/base.py
305
306
307
def append(self, value: ASTType) -> None:
    """Append a new node to the stack."""
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/packages.py
71
72
73
74
75
76
77
78
79
80
81
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    block_node = []

    for node in self.nodes:
        block_node.append(node.get_struct(simplified))

    key = f"MODULE[{self.name}]"
    value = cast(ReprStruct, block_node)

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

MutabilityKind

Bases: Enum

Definition for different kind of mutability.

Number

Number(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: AnyType

Number data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

OperatorType

OperatorType(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: DataType

AST main expression class.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Package

Package(name: str = 'main', modules: list[Module] = [], packages: list[Package] = [], loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: ASTNodes

AST class for Package.

Methods:

  • append

    Append a new node to the stack.

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/packages.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def __init__(
    self,
    name: str = "main",
    modules: list[Module] = [],
    packages: list[Package] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize the AST instance."""
    super().__init__(loc=loc)
    self.name = name
    self.modules = copy.deepcopy(modules)
    self.packages = copy.deepcopy(packages)

append

append(value: ASTType) -> None

Append a new node to the stack.

Source code in src/astx/base.py
305
306
307
def append(self, value: ASTType) -> None:
    """Append a new node to the stack."""
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/packages.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    packages = []
    modules = []

    for package in self.packages:
        packages.append(package.get_struct(simplified))

    for module in self.modules:
        modules.append(module.get_struct(simplified))

    key = str(self)
    value = cast(
        ReprStruct,
        {
            "modules": modules,
            "packages": packages,
        },
    )

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Program

Program(name: str = 'main', target: Target = Target('', ''), modules: list[Module] = [], packages: list[Package] = [], loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Package

AST class for Program.

Methods:

  • append

    Append a new node to the stack.

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/packages.py
140
141
142
143
144
145
146
147
148
149
150
151
152
def __init__(
    self,
    name: str = "main",
    target: Target = Target("", ""),
    modules: list[Module] = [],
    packages: list[Package] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize the AST instance."""
    super().__init__(
        name=name, modules=modules, packages=packages, loc=loc
    )
    self.target = copy.deepcopy(target)

append

append(value: ASTType) -> None

Append a new node to the stack.

Source code in src/astx/base.py
305
306
307
def append(self, value: ASTType) -> None:
    """Append a new node to the stack."""
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/packages.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    packages = []
    modules = []

    for package in self.packages:
        packages.append(package.get_struct(simplified))

    for module in self.modules:
        modules.append(module.get_struct(simplified))

    key = str(self)
    value = cast(
        ReprStruct,
        {
            "modules": modules,
            "packages": packages,
        },
    )

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ScopeKind

Bases: Enum

Definition for different kind of scopes.

SignedInteger

SignedInteger(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Integer

Signed integer number data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

StatementType

StatementType(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: AST

AST main expression class.

Methods:

  • get_struct

    Return a structure that represents the node object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
180
181
182
183
184
185
186
187
188
189
190
191
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the AST instance."""
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct abstractmethod

get_struct(simplified: bool = False) -> ReprStruct

Return a structure that represents the node object.

Source code in src/astx/base.py
255
256
257
@abstractmethod
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a structure that represents the node object."""

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Target

Target(datalayout: str, triple: str)

Bases: Expr

Define the Architecture target for the program.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/packages.py
33
34
35
36
37
def __init__(self, datalayout: str, triple: str) -> None:
    """Initialize the AST instance."""
    super().__init__()
    self.datalayout = datalayout
    self.triple = triple

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/packages.py
39
40
41
42
43
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    key = "TARGET"
    value = f"{self.datalayout}, {self.triple}"
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Time

Time(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Temporal

Time data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Timestamp

Timestamp(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Temporal

Timestamp data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

TypeCastExpr

TypeCastExpr(expr: Expr, target_type: DataType, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

AST class for type casting expressions.

Methods:

  • get_struct

    Return the AST structure of the TypeCast expression.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/types/casting.py
29
30
31
32
33
34
35
36
37
38
39
def __init__(
    self,
    expr: Expr,
    target_type: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc=loc, parent=parent)
    self.expr = expr
    self.target_type = target_type
    self.kind = ASTKind.TypeCastExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the TypeCast expression.

Source code in src/astx/types/casting.py
45
46
47
48
49
50
51
52
53
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the TypeCast expression."""
    key = "TypeCastExpr"
    value: ReprStruct = {
        "expression": self.expr.get_struct(simplified),
        "target_type": self.target_type.get_struct(simplified),
    }

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UInt128

UInt128(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: UnsignedInteger

UInt128 data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UInt16

UInt16(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: UnsignedInteger

UInt16 data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UInt32

UInt32(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: UnsignedInteger

UInt32 data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UInt64

UInt64(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: UnsignedInteger

UInt64 data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UInt8

UInt8(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: UnsignedInteger

UInt8 data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UTF8Char

UTF8Char(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: AnyType

Class for UTF-8 encoded characters.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UTF8String

UTF8String(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: AnyType

Class for UTF-8 encoded strings.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UnaryOp

UnaryOp(op_code: str, operand: DataType, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: DataTypeOps

AST class for the unary operator.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/types/operators.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def __init__(
    self,
    op_code: str,
    operand: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize the UnaryOp instance."""
    super().__init__()
    self.loc = loc
    self.op_code = op_code
    self.operand = operand
    self.kind = ASTKind.UnaryOpKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/types/operators.py
110
111
112
113
114
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    key = f"UNARY[{self.op_code}]"
    value = self.operand.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Undefined

Undefined(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

Undefined expression class.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
180
181
182
183
184
185
186
187
188
189
190
191
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the AST instance."""
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
354
355
356
357
358
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    value = "UNDEFINED"
    key = "UNDEFINED"
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UnsignedInteger

UnsignedInteger(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Integer

Unsigned integer number data type expression.

Methods:

  • get_struct

    Return a simple structure that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/base.py
388
389
390
391
392
393
394
395
396
397
398
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = ExprType()
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
404
405
406
407
408
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = f"DATA-TYPE[{self.__class__.__name__}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Variable

Variable(name: str, type_: DataType = AnyType(), loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: DataTypeOps

AST class for the variable usage.

Methods:

  • get_struct

    Return a string that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/variables.py
161
162
163
164
165
166
167
168
169
170
171
def __init__(
    self,
    name: str,
    type_: DataType = AnyType(),
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the Variable instance."""
    super().__init__(loc=loc, parent=parent)
    self.name = name
    self.type_ = type_

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a string that represents the object.

Source code in src/astx/variables.py
177
178
179
180
181
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a string that represents the object."""
    key = f"Variable[{self.name}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

VariableAssignment

VariableAssignment(name: str, value: Expr, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for variable declaration.

Methods:

  • get_struct

    Return a string that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/variables.py
128
129
130
131
132
133
134
135
136
137
138
139
140
def __init__(
    self,
    name: str,
    value: Expr,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the VarExprAST instance."""
    super().__init__(loc=loc, parent=parent)
    self.loc = loc
    self.name = name
    self.value = value
    self.kind = ASTKind.VariableAssignmentKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a string that represents the object.

Source code in src/astx/variables.py
146
147
148
149
150
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a string that represents the object."""
    key = str(self)
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

VariableDeclaration

VariableDeclaration(name: str, type_: DataType, mutability: MutabilityKind = constant, visibility: VisibilityKind = public, scope: ScopeKind = local, value: Expr = UNDEFINED, parent: Optional[ASTNodes] = None, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: StatementType

AST class for variable declaration.

Methods:

  • get_struct

    Return a string that represents the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/variables.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def __init__(
    self,
    name: str,
    type_: DataType,
    mutability: MutabilityKind = MutabilityKind.constant,
    visibility: VisibilityKind = VisibilityKind.public,
    scope: ScopeKind = ScopeKind.local,
    value: Expr = UNDEFINED,
    parent: Optional[ASTNodes] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize the VarExprAST instance."""
    super().__init__(loc=loc, parent=parent)
    self.mutability = mutability
    self.scope = scope
    self.visibility = visibility
    self.name = name
    self.type_ = type_
    self.value = value
    self.kind = ASTKind.VarDeclKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a string that represents the object.

Source code in src/astx/variables.py
66
67
68
69
70
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a string that represents the object."""
    key = str(self)
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

VisibilityKind

Bases: Enum

Definition of different kind of visibility.

WhileExpr

WhileExpr(condition: Expr, body: Block, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

AST class for while expression.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/flows.py
392
393
394
395
396
397
398
399
400
401
402
403
def __init__(
    self,
    condition: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the WhileExpr instance."""
    super().__init__(loc=loc, parent=parent)
    self.condition = condition
    self.body = body
    self.kind = ASTKind.WhileExprKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/flows.py
409
410
411
412
413
414
415
416
417
418
419
420
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    while_condition = self.condition.get_struct(simplified)
    while_body = self.body.get_struct(simplified)

    key = "WHILE-EXPR"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, while_condition),
        **cast(DictDataTypesStruct, while_body),
    }

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

WhileStmt

WhileStmt(condition: Expr, body: Block, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for while statement.

Methods:

  • get_struct

    Return the AST structure of the object.

  • to_json

    Return an json string that represents the object.

  • to_yaml

    Return an yaml string that represents the object.

Source code in src/astx/flows.py
353
354
355
356
357
358
359
360
361
362
363
364
def __init__(
    self,
    condition: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the WhileStmt instance."""
    super().__init__(loc=loc, parent=parent)
    self.condition = condition
    self.body = body
    self.kind = ASTKind.WhileStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/flows.py
370
371
372
373
374
375
376
377
378
379
380
381
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    while_condition = self.condition.get_struct(simplified)
    while_body = self.body.get_struct(simplified)

    key = "WHILE-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, while_condition),
        **cast(DictDataTypesStruct, while_body),
    }

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
265
266
267
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
259
260
261
262
263
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

get_version

get_version() -> str

Return the program version.

Source code in src/astx/__init__.py
141
142
143
144
145
146
def get_version() -> str:
    """Return the program version."""
    try:
        return importlib_metadata.version(__name__)
    except importlib_metadata.PackageNotFoundError:  # pragma: no cover
        return "0.17.0"  # semantic-release