File: mkapi.py

package info (click to toggle)
mu-editor 1.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,492 kB
  • sloc: python: 33,326; makefile: 154; xml: 32; sh: 7
file content (23 lines) | stat: -rwxr-xr-x 812 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python3
"""
Takes a JSON representation of an API and emits elements to be inserted into a
Python list such that they conform to Scintilla's API description DSL.
"""
import sys
import json


if __name__ == "__main__":
    f = sys.argv[1]
    with open(f) as api_file:
        api = json.load(api_file)
    # Sort the JSON objects so diffing code is easier to do.
    sorted_api = sorted(api, key=lambda k: k["name"])
    # Emit a representation of the API information in the format parsed by
    # the Scintilla.
    for i in sorted_api:
        name = i["name"]
        args = ", ".join(i["args"]) if i["args"] else ""
        description = i["description"].replace("\u2013", "--")
        content = repr("{}({}) \n{}".format(name, args, description))
        print("    _({}),".format(content))