Skip to content

string

Classes:

LiteralString

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

Bases: Literal

Methods:

Source code in packages/astx/src/astx/literals/string.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """
    title: Initialize LiteralString.
    parameters:
      value:
        type: str
      loc:
        type: SourceLocation
    """
    super().__init__(loc)
    self.value = value
    self.type_ = String()
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/string.py
62
63
64
65
66
67
68
69
70
71
72
73
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"LiteralString: {self.value}"
    value = self.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)
    )

LiteralUTF8Char

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

Bases: LiteralString

Methods:

Source code in packages/astx/src/astx/literals/string.py
142
143
144
145
146
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    super().__init__(value=value, loc=loc)
    self.type_ = UTF8Char()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/string.py
156
157
158
159
160
161
162
163
164
165
166
167
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the structure of the object in a simplified.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"LiteralUTF8Char: {self.value}"
    value = self.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)
    )

LiteralUTF8String

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

Bases: LiteralString

Methods:

Source code in packages/astx/src/astx/literals/string.py
95
96
97
98
99
def __init__(
    self, value: str, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    super().__init__(value=value, loc=loc)
    self.type_ = UTF8String()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/astx/src/astx/literals/string.py
109
110
111
112
113
114
115
116
117
118
119
120
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """
    title: Return the structure of the object in a simplified.
    parameters:
      simplified:
        type: bool
    returns:
      type: ReprStruct
    """
    key = f"LiteralUTF8String: {self.value}"
    value = self.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)
    )