io: add Tell() type
This commit is contained in:
parent
a3ff832f2b
commit
910be3c5ec
|
@ -21,7 +21,7 @@ from .types.seq import Arr, Tuple
|
|||
from .types.struct import StructType, Struct, Union
|
||||
from .types.transforms import Default, Preproc, Proc, Mapped, Enum, Check, Fixed
|
||||
from .types.control import Switch, If
|
||||
from .types.io import Sized, Terminated, Ref, AlignTo, AlignedTo, Lazy
|
||||
from .types.io import Sized, Terminated, Ref, AlignTo, AlignedTo, Lazy, Tell
|
||||
del types
|
||||
|
||||
# Compatibility
|
||||
|
|
|
@ -424,3 +424,23 @@ class AlignedTo(G[T], Wrapper[T]):
|
|||
|
||||
def __repr__(self) -> str:
|
||||
return f'{__name__}.AlignedTo({super().__repr__()}, alignment={self.alignment!r}, value={self.value!r})'
|
||||
|
||||
|
||||
class Tell(Type[Pos]):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def parse(self, context: Context, stream: Stream) -> Pos:
|
||||
return stream.tell()
|
||||
|
||||
def dump(self, context: Context, stream: Stream, value: Pos) -> None:
|
||||
pass
|
||||
|
||||
def sizeof(self, context: Context, value: O[Pos]) -> Pos:
|
||||
return 0
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f'tell()'
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'{__name__}.Tell()'
|
||||
|
|
Loading…
Reference in New Issue