From f62b105abd469561b30d50c33a4745d78f205b7c Mon Sep 17 00:00:00 2001 From: Midgard Date: Fri, 24 Jan 2020 14:47:53 +0100 Subject: [PATCH] HLDS: simplify data structure slightly --- app/hlds/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/hlds/__init__.py b/app/hlds/__init__.py index a45361d..fb0b307 100755 --- a/app/hlds/__init__.py +++ b/app/hlds/__init__.py @@ -9,8 +9,19 @@ with open(path.join(path.dirname(__file__), "hlds.tatsu")) as fh: GRAMMAR = fh.read() +def kind_comparer(compare_to): + return lambda item: item["kind"] == compare_to + + def parse(menu): - return tatsu_parse(GRAMMAR, menu) + parsed = tatsu_parse(GRAMMAR, menu) + return dict(( + *((att["key"], att["value"]) for att in parsed["attributes"]), + ("id", parsed["id"]), + ("name", parsed["name"]), + ("choices", filter(kind_comparer("choice_declaration"), parsed["items_"])), + ("bases", filter(kind_comparer("base"), parsed["items_"])), + )) def main(filename):