File: mkapi.py

package info (click to toggle)
mu-editor 1.0.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,044 kB
  • sloc: python: 16,323; makefile: 129; xml: 29; sh: 7
file content (23 lines) | stat: -rwxr-xr-x 812 bytes parent folder | download | duplicates (3)
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))