-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate.py
executable file
·130 lines (107 loc) · 3.68 KB
/
generate.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python3
"""
This file generates the geany filetype definition from the godot
documentation. This should make it easuer to keep it up to date. To run
it, you need to pass in the path to the documentation directory. For
example:
/generate.py ~/src/godot-docs
"""
import argparse
import configparser
import os
import sys
OUTFILE = 'filetypes.GDScript.conf'
HEADER = """\
Original Author: Matthias F. Brandstetter <[email protected]>
Copyright (C) 2014 Matthias F. Brandstetter <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.\
"""
def get_keywords(input_dir):
# TODO: Can we parse the gdscript_basics docs page for this?
return "and break class const continue elif else enum export extends false for func if in null or pass preload return self tool true var while static".split(" ")
def get_global_functions(input_dir):
functions = []
with open(input_dir+'/classes/[email protected]') as base_types:
for line in base_types.readlines():
pos = line.find('_class_@GDScript_')
if pos != -1:
end = line.find(':', pos)
functions.append(line[pos+len('_class_@GDScript_'):end])
return functions
def get_classes(input_dir):
classes = []
for file_name in os.listdir(input_dir+'/classes/'):
# capitilization means we will need to parse these files
if file_name.startswith('class_'):
with open(input_dir+'/classes/'+file_name) as class_data:
class_name = class_data.readlines()[6]
classes.append(class_name.strip())
return classes
def generate(input_dir):
config = configparser.ConfigParser()
config['styling'] = {
"default": "default",
"commentline": "comment_line",
"number": "number_1",
"string": "string_1",
"character": "character",
"word": "keyword_1",
"triple": "string_2",
"tripledouble": "string_2",
"classname": "type",
"defname": "function",
"operator": "operator",
"identifier": "identifier_1",
"commentblock": "comment",
"stringeol": "string_eol",
"word2": "keyword_2",
"decorator": "decorator",
}
IDENTIFIERS = get_global_functions(input_dir) + get_classes(input_dir)
PRIMARY = get_keywords(input_dir)
config['keywords'] = {
"primary": " ".join(p for p in PRIMARY),
"identifiers": " ".join(i for i in IDENTIFIERS)
}
config['lexer_properties'] = {
"fold.comment.python": 1,
"fold.quotes.python": 1
}
config['settings'] = {
"extension": "gd",
"lexer_filetype": "Python",
"comment_single": "#",
"comment_use_indent": False,
}
config['indentation'] = {
"width": 4,
"type": 1 # 1 is tabs
}
config['build_settigs'] = {
}
return config
def main(args):
parser = argparse.ArgumentParser(description='Generate geany file definition')
parser.add_argument('docs_dir', type=str, nargs=1,
help='Path to a clone of the godot-docs repo')
config = parser.parse_args(args)
with open(OUTFILE, 'w') as configfile:
for line in HEADER.split('\n'):
configfile.write('\n## ' + line)
configfile.write('\n\n')
with open(OUTFILE, 'a') as configfile:
config = generate(config.docs_dir[0])
config.write(configfile)
if __name__ == "__main__":
main(sys.argv[1:])