mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 18:53:06 +00:00
37 lines
762 B
Python
37 lines
762 B
Python
import re
|
|
from dataclasses import dataclass
|
|
|
|
from .error import MapParseError
|
|
|
|
REGEX_TYPEPATH = re.compile(r'^/[\w/]+$')
|
|
|
|
class Typepath:
|
|
path: str
|
|
segments: list[str]
|
|
|
|
def __init__(self, path):
|
|
if not REGEX_TYPEPATH.match(path):
|
|
raise MapParseError(f"Invalid typepath {path!r}.")
|
|
|
|
self.path = path
|
|
self.segments = path.split('/')[1:]
|
|
|
|
def __eq__(self, other):
|
|
if not isinstance(other, Typepath):
|
|
return False
|
|
|
|
return self.path == other.path
|
|
|
|
def __str__(self) -> str:
|
|
return self.path
|
|
|
|
@dataclass
|
|
class Filename:
|
|
path: str
|
|
|
|
@dataclass
|
|
class Null:
|
|
pass
|
|
|
|
Constant = str | int | float | Filename | Typepath | Null | list['Constant'] | dict['Constant', 'Constant']
|