From: Petr Špaček Date: Fri, 24 Jun 2022 13:05:02 +0000 (+0200) Subject: Pretty-print grammar for zones X-Git-Tag: v9.19.3~16^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0392144e995bb90d8fd8022c5243edc260bd7156;p=thirdparty%2Fbind9.git Pretty-print grammar for zones It turns out the tree of dictionaries is not the best structure to represent our grammar, unfortunatelly. The problem is that "zone" has several context-dependent variants which change meaning of "zone" based on inner field "type". Redesigning the whole structure does not seem to be worth, so I settled on this terrible hack. --- diff --git a/doc/arm/_ext/iscconf.py b/doc/arm/_ext/iscconf.py index 022d303de06..99f6b533aaa 100644 --- a/doc/arm/_ext/iscconf.py +++ b/doc/arm/_ext/iscconf.py @@ -173,8 +173,9 @@ def domain_factory(domainname, domainlabel, todolist, grammar): else: separator = "" paths = "" + subgrammar = grammar_grp[0].subgrammar grammar_txt = ( - self.isc_name + subgrammar.get("_pprint_name", self.isc_name) + " " + checkgrammar.pformat_grammar(grammar_grp[0].subgrammar, level=1) ) diff --git a/doc/arm/_ext/mergegrammar.py b/doc/arm/_ext/mergegrammar.py index 75146f7dc4b..966d1c3bc95 100644 --- a/doc/arm/_ext/mergegrammar.py +++ b/doc/arm/_ext/mergegrammar.py @@ -29,8 +29,9 @@ def read_zone(): assert len(zonegrammar) == 1 assert "zone" in zonegrammar zone_grammars[zone_type] = zonegrammar["zone"] + zone_grammars[zone_type]["_pprint_name"] = "zone" - return {"zone": {"_mapbody": zone_grammars}} + return {"zone": {"_mapbody": zone_grammars, "_ignore_this_level": True}} def read_main(): diff --git a/doc/misc/checkgrammar.py b/doc/misc/checkgrammar.py index 57f4c8ede5f..8483b2edaf8 100644 --- a/doc/misc/checkgrammar.py +++ b/doc/misc/checkgrammar.py @@ -113,19 +113,25 @@ def pformat_grammar(node, level=1): # a nested map out = "" indent = level * "\t" - if "_id" in node: - out += node["_id"] + " " - out += "{\n" - - for key in node["_mapbody"]: - out += f"{indent}{key}" - inner_grammar = pformat_grammar(node["_mapbody"][key], level=level + 1) + if not node.get("_ignore_this_level"): + if "_id" in node: + out += node["_id"] + " " + out += "{\n" + + for key, subnode in node["_mapbody"].items(): + if not subnode.get("_ignore_this_level"): + out += f"{indent}{subnode.get('_pprint_name', key)}" + inner_grammar = pformat_grammar(node["_mapbody"][key], level=level + 1) + else: # act as if we were not in a map + inner_grammar = pformat_grammar(node["_mapbody"][key], level=level) if inner_grammar[0] != ";": # we _did_ find some arguments out += " " out += inner_grammar - out += indent[:-1] + "};" # unindent the closing bracket - if "_flags" in node: - out += " // " + ", ".join(node["_flags"]) + + if not node.get("_ignore_this_level"): + out += indent[:-1] + "};" # unindent the closing bracket + if "_flags" in node: + out += " // " + ", ".join(node["_flags"]) return out + "\n"