diff --git a/app/hlds/models.py b/app/hlds/models.py index 13ad06c..510a53f 100644 --- a/app/hlds/models.py +++ b/app/hlds/models.py @@ -12,6 +12,11 @@ def _format_tags(tags): ) +def _format_type_and_choice(type_and_choice): + type_, choice = type_and_choice + return "{} {}".format(type_, choice) + + class Option: def __init__(self, id_, *, name, description, price, tags): self.id = id_ @@ -53,15 +58,15 @@ class Dish: self.price = price self.tags = tags - self.choices: List[Choice] = choices + self.choices: List[(str, Choice)] = choices def __str__(self): - return "{0.id}: {0.name}{1}{2}{3}\n\t{4}".format( + return "base {0.id}: {0.name}{1}{2}{3}\n\t{4}".format( self, " -- {}".format(self.description) if self.description else "", _format_tags(self.tags), " {}".format(self.price) if self.price else "", - "\n\t".join(map(str, self.choices)) + "\n\t".join(map(_format_type_and_choice, self.choices)) ) diff --git a/app/hlds/parser.py b/app/hlds/parser.py index 4127204..9792d93 100644 --- a/app/hlds/parser.py +++ b/app/hlds/parser.py @@ -23,9 +23,8 @@ class HldsSemanticActions: dishes = filter_instance(Dish, ast["items_"]) for dish in dishes: for i, choice in enumerate(dish.choices): - if not isinstance(choice, Choice): - assert "id" in choice - dish.choices[i] = choices[choice["id"]] + if not isinstance(choice[1], Choice): + dish.choices[i] = (dish.choices[i][0], choices[choice[1]]) return Location( ast["id"], @@ -53,7 +52,11 @@ class HldsSemanticActions: ) def indent_choice_block(self, ast): - return self.choice_block(ast) if ast["kind"] == "declaration" else ast + return ( + (ast["type"], self.choice_block(ast)) + if ast["kind"] == "declaration" else + (ast["type"], ast["id"]) + ) def indent_choice_entry(self, ast): return Option(