Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start working on Python support #76

Merged
merged 16 commits into from
Aug 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rewrite/rewrite/core/marker/markers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from dataclasses import dataclass
from typing import List, Protocol, ClassVar
from uuid import UUID
@@ -22,7 +23,7 @@ class Markers:
id: UUID
markers: List[Marker]

EMPTY: ClassVar = None
EMPTY: ClassVar[Markers] = None

def __eq__(self, other):
if self.__class__ == other.__class__:
@@ -33,5 +34,4 @@ def __hash__(self):
return hash(self.id)


# noinspection PyFinal
Markers.EMPTY = Markers(random_id(), [])
33 changes: 32 additions & 1 deletion rewrite/rewrite/properties/tree/tree.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations
from dataclasses import dataclass, replace
from typing import Protocol
from typing import Protocol, Optional
from uuid import UUID
from enum import Enum

from ...core import Tree, SourceFile
from ...core.marker.markers import Markers, Marker
@@ -10,6 +12,10 @@ class Properties(Tree, Protocol):
pass


class Content(Properties, Protocol):
pass


@dataclass(eq=False, frozen=True)
class File(Properties, SourceFile):
id: UUID
@@ -28,3 +34,28 @@ def with_markers(self, value: Markers):

def with_source_path(self, value: str):
return self if self.source_path == value else replace(self, source_path=value)


class Delimiter(Enum):
COLON = ':'
EQUALS = '='
NONE = '\0'


@dataclass(eq=False, frozen=True)
class Entry(Content):
id: UUID
prefix: str
markers: Markers
key: str
before_equals: str
delimiter: Optional[Delimiter]
value: Value


@dataclass(eq=False, frozen=True)
class Value:
id: UUID
prefix: str
markers: Markers
text: str