Skip to content

packages

Classes:

AliasExpr

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

Bases: Expr

Methods:

Source code in packages/astx/src/astx/packages.py
291
292
293
294
295
296
297
298
299
300
301
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
Source code in packages/astx/src/astx/packages.py
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the alias.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    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
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    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

Methods:

Source code in packages/astx/src/astx/packages.py
469
470
471
472
473
474
475
476
477
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
Source code in packages/astx/src/astx/packages.py
488
489
490
491
492
493
494
495
496
497
498
499
500
501
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the import expression.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    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
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    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

Methods:

Source code in packages/astx/src/astx/packages.py
526
527
528
529
530
531
532
533
534
535
536
537
538
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
Source code in packages/astx/src/astx/packages.py
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the import-from expression.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    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
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    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

Methods:

Source code in packages/astx/src/astx/packages.py
404
405
406
407
408
409
410
411
412
413
414
415
416
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
Source code in packages/astx/src/astx/packages.py
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the import-from statement.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    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
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    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

Methods:

Source code in packages/astx/src/astx/packages.py
347
348
349
350
351
352
353
354
355
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
Source code in packages/astx/src/astx/packages.py
366
367
368
369
370
371
372
373
374
375
376
377
378
379
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the import statement.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    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
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Module

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

Bases: Block

Methods:

Attributes:

Source code in packages/astx/src/astx/packages.py
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def __init__(
    self,
    name: str = "main",
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      name:
        type: str
      loc:
        type: SourceLocation
    """
    super().__init__(name=name, loc=loc)
    self.kind = ASTKind.ModuleKind

block property

block: list[AST]

append

append(value: ASTType) -> None
Source code in packages/astx/src/astx/base.py
484
485
486
487
488
489
490
491
def append(self, value: ASTType) -> None:
    """
    title: Append a new node to the stack.
    parameters:
      value:
        type: ASTType
    """
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    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
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    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

Methods:

Source code in packages/astx/src/astx/packages.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def __init__(
    self,
    name: str = "main",
    modules: list[Module] = [],
    packages: list[Package] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      name:
        type: str
      modules:
        type: list[Module]
      packages:
        type: list[Package]
      loc:
        type: SourceLocation
    """
    super().__init__(loc=loc)
    self.name = name
    self.modules = copy.deepcopy(modules)
    self.packages = copy.deepcopy(packages)

append

append(value: ASTType) -> None
Source code in packages/astx/src/astx/base.py
484
485
486
487
488
489
490
491
def append(self, value: ASTType) -> None:
    """
    title: Append a new node to the stack.
    parameters:
      value:
        type: ASTType
    """
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    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
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    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

Methods:

Source code in packages/astx/src/astx/packages.py
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
def __init__(
    self,
    name: str = "main",
    target: Target = Target("", ""),
    modules: list[Module] = [],
    packages: list[Package] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      name:
        type: str
      target:
        type: Target
      modules:
        type: list[Module]
      packages:
        type: list[Package]
      loc:
        type: SourceLocation
    """
    super().__init__(
        name=name, modules=modules, packages=packages, loc=loc
    )
    self.target = copy.deepcopy(target)

append

append(value: ASTType) -> None
Source code in packages/astx/src/astx/base.py
484
485
486
487
488
489
490
491
def append(self, value: ASTType) -> None:
    """
    title: Append a new node to the stack.
    parameters:
      value:
        type: ASTType
    """
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    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
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Target

Target(datalayout: str, triple: str)

Bases: Expr

Methods:

Source code in packages/astx/src/astx/packages.py
42
43
44
45
46
47
48
49
50
51
52
53
def __init__(self, datalayout: str, triple: str) -> None:
    """
    title: Initialize the AST instance.
    parameters:
      datalayout:
        type: str
      triple:
        type: str
    """
    super().__init__()
    self.datalayout = datalayout
    self.triple = triple

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/packages.py
55
56
57
58
59
60
61
62
63
64
65
66
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = "TARGET"
    value = f"{self.datalayout}, {self.triple}"
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )