summaryrefslogtreecommitdiff
path: root/src/libs/3rdparty/syntax-highlighting/data/generators/qmake-gen.py
blob: a16d5fd5d44b644c0e6db1659f28282eed32802c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python

# SPDX-FileCopyrightText: 2016 Kevin Funk <kfunk@kde.org>
#
# SPDX-License-Identifier: LGPL-2.0-or-later

# This script will print XML-like code you can put into the qmake.xml
# syntax definition file
#
# Prerequisite: You need to have a qtbase checkout somewhere
#
# Usage: qmake-gen.py /path/to/qtbase/

from __future__ import print_function

import subprocess
import os
import sys

qt5Source = sys.argv[1]

qmakeKeywords = subprocess.check_output("ag --nofilename 'QMAKE_[A-Z_0-9]+' {0}/mkspecs -o".format(qt5Source), shell=True).split(os.linesep)
extraKeywords = subprocess.check_output("sed -nr 's/\\\section1 ([A-Z_0-9]{{2,100}}).*/\\1/p' {0}/qmake/doc/src/qmake-manual.qdoc".format(qt5Source), shell=True).split(os.linesep)
keywords = []
keywords = [x.strip() for x in qmakeKeywords]
keywords += [x.strip() for x in extraKeywords]
keywords = list(set(keywords)) # remove duplicates
keywords.sort()

functions = subprocess.check_output("sed -nr 's/\{{ \\\"(.+)\\\", T_.+/\\1/p' {0}/qmake/library/qmakebuiltins.cpp".format(qt5Source), shell=True).split(os.linesep)
functions.sort()

def printItems(container):
    for item in container:
        trimmedText = item.strip()
        if not trimmedText:
            continue

        print("<item> %s </item>" % trimmedText)
    print()

print("KEYWORDS")
printItems(keywords)

print("FUNCTIONS")
printItems(functions)