diff options
Diffstat (limited to 'std')
-rwxr-xr-x | std/generate_map.py | 48 | ||||
-rwxr-xr-x | std/generate_map.sh | 20 |
2 files changed, 48 insertions, 20 deletions
diff --git a/std/generate_map.py b/std/generate_map.py new file mode 100755 index 0000000..62c9920 --- /dev/null +++ b/std/generate_map.py @@ -0,0 +1,48 @@ +#!/bin/env python + +from pathlib import Path +import json + + +def list_defs(path, kind, prefix): + res = [] + for line in open(path).readlines(): + if line.startswith(":input"): + parts = line.split(" ") + input_path = parts[1].strip().split("std/")[1] + ".bruijn" + # not using kind="input" is important, "import"s should be inherited + res = res + list_defs(input_path, kind, prefix) + elif line.startswith(":import") and kind == "input": + parts = line.split(" ") + import_path = parts[1].strip().split("std/")[1] + ".bruijn" + new_prefix = ( + "" if parts[2].strip() == "." else parts[2].strip() + "." + ) + new_prefix = prefix + new_prefix if prefix else new_prefix + res = res + list_defs(import_path, "import", new_prefix) + elif ( + line.startswith(":") + or line.startswith("#") + or line.strip() == "" + or line[0].isspace() + ): + continue + else: + parts = line.strip().split(" ") + res.append( + { + "name": prefix + parts[0], + "source": path, + "kind": kind, + } + ) + return res + + +res = {} +files = Path(".").glob("**/*.bruijn") +for file in files: + path = str(file) + if path != "All.bruijn" and "Generic" not in path: + res[path] = list_defs(path, "input", "") +print(json.dumps(res)) diff --git a/std/generate_map.sh b/std/generate_map.sh deleted file mode 100755 index 193a62b..0000000 --- a/std/generate_map.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -FILES="$(find * -type f -name "*.bruijn" ! -name "All.bruijn" ! -path "*Generic*")" - -# TODO: also handle imports for :input intelligence -list_defs() { - grep -Po "^[^:# \t][^ \t]*" "$1" | sed -e "s#\\(.*\\)#{\"name\": \"\\1\", \"source\": \"$1\"}#g" - inputs="$(awk '/^:input/ {print $2}' "$1")" - for i in $inputs; do - list_defs "${i#std/}.bruijn" - done -} - -{ - for f in $FILES; do - echo "{\"$f\":" - list_defs "$f" | sed 's/\\/\\\\/g' | jq -s . - echo "}" - done -} | jq -s add |