diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-15 14:04:10 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-22 19:18:38 -0600 |
commit | d912a4d79ed9e51e5dfcc24e6445c1de7dbb1a30 (patch) | |
tree | 4d9604cdfa7269cf827b87301e9a685a55c6da2e /lib9p/idl | |
parent | 185c3329145959433b8b805de5f114b66b8fcaee (diff) |
lib9p: idl.gen: Have a separate type that excludes idl.Primitive
Diffstat (limited to 'lib9p/idl')
-rw-r--r-- | lib9p/idl/__init__.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lib9p/idl/__init__.py b/lib9p/idl/__init__.py index 042a438..04e1791 100644 --- a/lib9p/idl/__init__.py +++ b/lib9p/idl/__init__.py @@ -271,6 +271,7 @@ class Message(Struct): type Type = Primitive | Number | Bitfield | Struct | Message +type UserType = Number | Bitfield | Struct | Message T = typing.TypeVar("T", Number, Bitfield, Struct, Message) # Parse ######################################################################## @@ -417,8 +418,8 @@ re_line_cont = f"\\s+{re_string('specs')}" # could be bitfield/struct/msg def parse_file( - filename: str, get_include: typing.Callable[[str], tuple[str, list[Type]]] -) -> tuple[str, list[Type]]: + filename: str, get_include: typing.Callable[[str], tuple[str, list[UserType]]] +) -> tuple[str, list[UserType]]: version: str | None = None env: dict[str, Type] = { "1": Primitive.u8, @@ -577,7 +578,7 @@ def parse_file( if not version: raise SyntaxError("must have exactly 1 version line") - typs: list[Type] = [x for x in env.values() if not isinstance(x, Primitive)] + typs: list[UserType] = [x for x in env.values() if not isinstance(x, Primitive)] for typ in [typ for typ in typs if isinstance(typ, Struct)]: valid_syms = [ @@ -607,21 +608,21 @@ def parse_file( class Parser: - cache: dict[str, tuple[str, list[Type]]] = {} + cache: dict[str, tuple[str, list[UserType]]] = {} - def parse_file(self, filename: str) -> tuple[str, list[Type]]: + def parse_file(self, filename: str) -> tuple[str, list[UserType]]: filename = os.path.normpath(filename) if filename not in self.cache: - def get_include(other_filename: str) -> tuple[str, list[Type]]: + def get_include(other_filename: str) -> tuple[str, list[UserType]]: return self.parse_file(os.path.join(filename, "..", other_filename)) self.cache[filename] = parse_file(filename, get_include) return self.cache[filename] - def all(self) -> tuple[set[str], list[Type]]: + def all(self) -> tuple[set[str], list[UserType]]: ret_versions: set[str] = set() - ret_typs: dict[str, Type] = {} + ret_typs: dict[str, UserType] = {} for version, typs in self.cache.values(): if version in ret_versions: raise ValueError(f"duplicate protocol version {repr(version)}") |