Debian Codegraph @

doc/arm/_ext/mergegrammar.py

raw
1 ############################################################################
2 # Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 #
4 # SPDX-License-Identifier: MPL-2.0
5 #
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, you can obtain one at https://mozilla.org/MPL/2.0/.
9 #
10 # See the COPYRIGHT file distributed with this work for additional
11 # information regarding copyright ownership.
12 ############################################################################
13
14 # Depends on CWD - Sphinx plugin
15
16 from pathlib import Path
17
18 import json
19
20 import parsegrammar
21
22
23 def read_zone():
24 zone_grammars = {}
25 for file in Path("../misc/").glob("*.zoneopt"):
26 # in-view is not really a zone type
27 if file.stem == "in-view":
28 zone_type = "in-view"
29 else:
30 zone_type = f"type {file.stem}"
31
32 with file.open(encoding="ascii") as fp:
33 zonegrammar = parsegrammar.parse_mapbody(fp)
34 assert len(zonegrammar) == 1
35 assert "zone" in zonegrammar
36 zone_grammars[zone_type] = zonegrammar["zone"]
37 zone_grammars[zone_type]["_pprint_name"] = "zone"
38
39 return {"zone": {"_mapbody": zone_grammars, "_ignore_this_level": True}}
40
41
42 def read_main():
43 with Path("../misc/options").open(encoding="ascii") as fp:
44 optgrammar = parsegrammar.parse_mapbody(fp)
45 return optgrammar
46
47
48 def combine():
49 zones = read_zone()
50 assert zones
51 rest = read_main()
52 assert rest
53 rest.update(zones)
54
55 # this is a terrible hack
56 # but cfg_test cannot print zone grammars inside view
57 rest["view"]["_mapbody"].update(zones)
58
59 return rest
60
61
62 if __name__ == "__main__":
63 full_grammar = combine()
64 print(json.dumps(full_grammar))