This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""Jaclang Runtimelib Implementation.""" | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass, field | ||
from uuid import UUID, uuid4 | ||
from typing import Type | ||
|
||
from .interface import ( | ||
JID as _JID, | ||
Anchor as _Anchor, | ||
_ANCHOR, | ||
NodeAnchor as _NodeAnchor, | ||
EdgeAnchor as _EdgeAnchor, | ||
WalkerAnchor as _WalkerAnchor, | ||
Architype as _Architype, | ||
NodeArchitype as _NodeArchitype, | ||
EdgeArchitype as _EdgeArchitype, | ||
WalkerArchitype as _WalkerArchitype, | ||
) | ||
|
||
|
||
@dataclass | ||
class JID(_JID[UUID, _ANCHOR]): | ||
"""Jaclang Default JID.""" | ||
|
||
id: UUID | ||
type: Type[_ANCHOR] | ||
|
||
@property | ||
def anchor(self) -> _ANCHOR | None: | ||
"""Get anchor by id and type.""" | ||
return None | ||
|
||
def __repr__(self) -> str: | ||
"""Override string representation.""" | ||
return f"{self.type.__class__.__name__[:1].lower()}:{self.name}:{self.id}" | ||
|
||
def __str__(self) -> str: | ||
"""Override string parsing.""" | ||
return f"{self.type.__class__.__name__[:1].lower()}:{self.name}:{self.id}" | ||
|
||
|
||
@dataclass | ||
class NodeAnchor(_NodeAnchor[JID]): | ||
"""NodeAnchor Interface.""" | ||
|
||
edge_ids: list[JID["EdgeAnchor"]] | ||
|
||
|
||
@dataclass | ||
class EdgeAnchor(_EdgeAnchor[JID]): | ||
"""NodeAnchor Interface.""" | ||
|
||
source_id: JID["NodeAnchor"] | ||
target_id: JID["NodeAnchor"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
"""Jaclang Runtimelib interfaces.""" | ||
|
||
from abc import ABC, abstractmethod | ||
from dataclasses import dataclass | ||
from typing import Generic, Iterable, Type, TypeVar | ||
|
||
_ID = TypeVar("_ID") | ||
_ANCHOR = TypeVar("_ANCHOR", bound="Anchor") | ||
_ARCHITYPE = TypeVar("_ARCHITYPE", bound="Architype") | ||
|
||
_BASE_ANCHOR = TypeVar("_BASE_ANCHOR", bound="Anchor") | ||
|
||
_SERIALIZE = TypeVar("_SERIALIZE") | ||
_DESERIALIZE = TypeVar("_DESERIALIZE") | ||
|
||
|
||
@dataclass(eq=False, repr=False, kw_only=True) | ||
class JID(Generic[_ID, _ANCHOR], ABC): | ||
"""Jaclang ID Interface.""" | ||
|
||
id: _ID | ||
type: Type[_ANCHOR] | ||
name: str | ||
|
||
@property | ||
@abstractmethod | ||
def anchor(self) -> _ANCHOR | None: | ||
"""Get anchor by id and type.""" | ||
|
||
@abstractmethod | ||
def __repr__(self) -> str: | ||
"""Override string representation.""" | ||
|
||
@abstractmethod | ||
def __str__(self) -> str: | ||
"""Override string parsing.""" | ||
|
||
@abstractmethod | ||
def __eq__(self, value: object) -> bool: | ||
"""Override equal operation.""" | ||
|
||
|
||
@dataclass | ||
class Anchor(Generic[_ID, _ARCHITYPE, _SERIALIZE], ABC): | ||
"""Anchor Interface.""" | ||
|
||
jid: JID[_ID, "Anchor"] | ||
architype: _ARCHITYPE | ||
|
||
@abstractmethod | ||
def __serialize__(self) -> _SERIALIZE: | ||
"""Override string representation.""" | ||
|
||
@classmethod | ||
@abstractmethod | ||
def __deserialize__(cls: Type[_DESERIALIZE], data: _SERIALIZE) -> _DESERIALIZE: | ||
"""Override string parsing.""" | ||
|
||
|
||
@dataclass | ||
class NodeAnchor(Anchor[_ID, "NodeArchitype", _SERIALIZE]): | ||
"""NodeAnchor Interface.""" | ||
|
||
edge_ids: Iterable[JID[_ID, "EdgeAnchor"]] | ||
|
||
|
||
@dataclass | ||
class EdgeAnchor(Anchor[_ID, "EdgeArchitype", _SERIALIZE]): | ||
"""EdgeAnchor Interface.""" | ||
|
||
source_id: JID[_ID, "NodeAnchor"] | ||
target_id: JID[_ID, "NodeAnchor"] | ||
|
||
|
||
@dataclass | ||
class WalkerAnchor(Anchor[_ID, "WalkerArchitype", _SERIALIZE]): | ||
"""WalkerAnchor Interface.""" | ||
|
||
|
||
class Architype(Generic[_BASE_ANCHOR, _SERIALIZE], ABC): | ||
"""Architype Interface.""" | ||
|
||
__jac__: _BASE_ANCHOR | ||
|
||
@abstractmethod | ||
def __serialize__(self) -> _SERIALIZE: | ||
"""Override string representation.""" | ||
|
||
@classmethod | ||
@abstractmethod | ||
def __deserialize__(cls: Type[_DESERIALIZE], data: _SERIALIZE) -> _DESERIALIZE: | ||
"""Override string parsing.""" | ||
|
||
|
||
class NodeArchitype(Architype[NodeAnchor, _SERIALIZE]): | ||
"""NodeArchitype Interface.""" | ||
|
||
|
||
class EdgeArchitype(Architype[EdgeAnchor, _SERIALIZE]): | ||
"""EdgeArchitype Interface.""" | ||
|
||
|
||
class WalkerArchitype(Architype[WalkerAnchor, _SERIALIZE]): | ||
"""Walker Architype Interface.""" |