Skip to content

Commit

Permalink
Add string name warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kg583 committed Jan 10, 2024
1 parent 67f7e4d commit 09c7496
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tivars/types/tokenized.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,20 @@ def __init__(self, init=None, *,

super().__init__(init, for_flash=for_flash, name=name, version=version, archived=archived, data=data)

@Section(8, TokenizedString)
def name(self, value) -> str:
"""
The name of the entry
Must be one of the string names: ``Str1`` - ``Str0``
"""

if not re.fullmatch(r"Str\d", varname := value[:4].capitalize()):
warn(f"String has an invalid name: {varname}.",
BytesWarning)

return varname

@Loader[str]
def load_string(self, string: str, *, model: TIModel = None):
super().load_string(string.strip("\"'"))
Expand Down Expand Up @@ -326,7 +340,7 @@ def name(self, value) -> str:
varname = re.sub(r"[^θa-zA-Z0-9]", "", varname)

if not varname or varname[0].isnumeric():
warn(f"Var has invalid name: {varname}.",
warn(f"Program has invalid an name: {varname}.",
BytesWarning)

return varname
Expand Down

0 comments on commit 09c7496

Please sign in to comment.