Skip to content

string

ASTx Data Types module.

Classes:

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)
    )