parrot/position.py

29 lines
542 B
Python
Raw Normal View History

2023-04-06 03:17:57 +01:00
from __future__ import annotations
from typing import NamedTuple, TypeVar, Generic
class Position(NamedTuple):
index: int
line: int
col: int
class Span(NamedTuple):
begin: Position
end: Position
def to(self, end: Span) -> Span:
return Span(self.begin, end.end)
T = TypeVar("T")
class Node(Generic[T]):
def __init__(self, value: T, span: Span) -> None:
super().__init__()
self.value = value
self.span = span
def __str__(self) -> str:
return self.value.__str__()