tighten things up
This commit is contained in:
parent
beea56fad5
commit
9f29067f6d
1 changed files with 11 additions and 34 deletions
|
@ -41,13 +41,11 @@ class TokenBase(object):
|
||||||
"""The raw token as scanned."""
|
"""The raw token as scanned."""
|
||||||
|
|
||||||
|
|
||||||
class ConstTokenBase(TokenBase):
|
class ConstTokenBase(TokenBase, NamedTuple):
|
||||||
"""The shared interface for constant tokens"""
|
"""The shared interface for constant tokens"""
|
||||||
|
data: Any
|
||||||
@property
|
raw: str
|
||||||
@abstractmethod
|
pos: Position
|
||||||
def data(self) -> Any:
|
|
||||||
"""The value of the token."""
|
|
||||||
|
|
||||||
# Hash according to data
|
# Hash according to data
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
|
@ -64,53 +62,32 @@ class ConstTokenBase(TokenBase):
|
||||||
return self.data > other
|
return self.data > other
|
||||||
|
|
||||||
|
|
||||||
class BooleanToken(ConstTokenBase, Enum):
|
class BooleanToken(ConstTokenBase):
|
||||||
"""A read boolean."""
|
"""A read boolean."""
|
||||||
data: bool
|
|
||||||
raw: str
|
|
||||||
pos: Position
|
|
||||||
|
|
||||||
|
|
||||||
class IntegerToken(ConstTokenBase, NamedTuple):
|
class IntegerToken(ConstTokenBase):
|
||||||
"""A read integer, including position."""
|
"""A read integer, including position."""
|
||||||
data: int
|
|
||||||
raw: str
|
|
||||||
pos: Position
|
|
||||||
|
|
||||||
|
|
||||||
class FractionToken(ConstTokenBase, NamedTuple):
|
class FractionToken(ConstTokenBase):
|
||||||
"""A read fraction, including position."""
|
"""A read fraction, including position."""
|
||||||
data: Fraction
|
|
||||||
raw: str
|
|
||||||
pos: Position
|
|
||||||
|
|
||||||
|
|
||||||
class FloatToken(ConstTokenBase, NamedTuple):
|
class FloatToken(ConstTokenBase):
|
||||||
"""A read floating point number, including position."""
|
"""A read floating point number, including position."""
|
||||||
data: float
|
|
||||||
raw: str
|
|
||||||
pos: Position
|
|
||||||
|
|
||||||
|
|
||||||
class SymbolToken(ConstTokenBase, NamedTuple):
|
class SymbolToken(ConstTokenBase):
|
||||||
"""A read symbol, including position."""
|
"""A read symbol, including position."""
|
||||||
data: str
|
|
||||||
raw: str
|
|
||||||
pos: Position
|
|
||||||
|
|
||||||
|
|
||||||
class KeywordToken(ConstTokenBase, NamedTuple):
|
class KeywordToken(ConstTokenBase):
|
||||||
"""A read keyword."""
|
"""A read keyword."""
|
||||||
data: str
|
|
||||||
raw: str
|
|
||||||
pos: Position
|
|
||||||
|
|
||||||
|
|
||||||
class StringToken(ConstTokenBase, NamedTuple):
|
class StringToken(ConstTokenBase):
|
||||||
"""A read string, including position."""
|
"""A read string, including position."""
|
||||||
data: str
|
|
||||||
raw: str
|
|
||||||
pos: Position
|
|
||||||
|
|
||||||
|
|
||||||
class ListType(Enum):
|
class ListType(Enum):
|
||||||
|
|
Loading…
Reference in a new issue