From eb61663888ba5409a4dd309a1ca8c859fe63a828 Mon Sep 17 00:00:00 2001 From: Correl Date: Sat, 17 Jul 2021 00:56:15 -0400 Subject: [PATCH] Add support for colorless searches --- tutor/models.py | 5 +++-- tutor/search.py | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tutor/models.py b/tutor/models.py index 342f5f6..a839a32 100644 --- a/tutor/models.py +++ b/tutor/models.py @@ -7,6 +7,7 @@ import uuid class Color(enum.IntEnum): + Colorless = 0 White = 1 Blue = 2 Black = 3 @@ -14,7 +15,7 @@ class Color(enum.IntEnum): Red = 5 def __str__(self) -> str: - return dict(zip(Color, "WUBGR")).get(self.value) + return dict(zip(Color, "CWUBGR")).get(self.value).replace("C", "") @staticmethod def to_string(colors: typing.List["Color"]) -> str: @@ -24,7 +25,7 @@ class Color(enum.IntEnum): def from_string(colors: str) -> typing.List["Color"]: return [ color - for color in [dict(zip("WUBGR", Color)).get(c) for c in colors.upper()] + for color in [dict(zip("CWUBGR", Color)).get(c) for c in colors.upper()] if color is not None ] diff --git a/tutor/search.py b/tutor/search.py index 7f67c91..965abcf 100644 --- a/tutor/search.py +++ b/tutor/search.py @@ -60,7 +60,8 @@ ustring = functools.partial(parsy.string, transform=lambda s: s.upper()) lstring_from = functools.partial(parsy.string_from, transform=lambda s: s.lower()) ustring_from = functools.partial(parsy.string_from, transform=lambda s: s.upper()) -W, U, B, G, R = ( +C, W, U, B, G, R = ( + tutor.models.Color.Colorless, tutor.models.Color.White, tutor.models.Color.Blue, tutor.models.Color.Black, @@ -73,7 +74,8 @@ gte = parsy.string(">=").map(Operator) lte = parsy.string("<=").map(Operator) color = ( - ustring("w").result(W) + ustring("c").result(C) + | ustring("w").result(W) | ustring("u").result(U) | ustring("b").result(B) | ustring("g").result(G) @@ -83,7 +85,8 @@ color = ( multicolor = color.many() single_color = ( - lstring("white").result({W}) + lstring("colorless").result({C}) + | lstring("white").result({W}) | lstring("blue").result({U}) | lstring("black").result({B}) | lstring("green").result({G})