#!/usr/bin/env python3 import sys from json import loads def format(name, comment, signature): def parse_sig(sig): def parse_arg(arg): def parse_type(ty): i = ty.find("(") ty, name = ty[:i].strip().lower(), ty[i+1:].strip(" )") if name == "": return "()" return f"{name}:{ty}" i = arg.find("(") pre, arg_list = arg[:i], arg[i+1:].split(",") args = ", ".join(map(parse_type, arg_list)) if args.count(",") >= 1: args = f"({args})" return f"{args}" def parse_ret(ret): return ret.replace("Type :: ", "").lower() args, ret = sig.split("->") args = ", ".join(map(parse_arg, args[1:-2].split(")),"))) ret = parse_ret(ret) return f"
  • fn {args} -> {ret}
  • " sigs = "\n".join(parse_sig(sig) for sig in signature) return f"""

    {name}

    {comment}
    """ def tok(name, **_): return f"
  • {name}
  • " preamble = f""" Lingon Sylt documentation

    THE Lingon Sylt documentation

    """ postamble = """ """ def main(args): if len(args) != 2: print("Usage: {} docs.json", args[0]) sys.exit(1) with open("docs.html", "w") as docs: docs.write(preamble) docs.write("") for element in loads(open(args[1]).read()): docs.write(format(**element)) docs.write(postamble) if __name__ == "__main__": main(sys.argv)