Skip to content

Commit 338cc01

Browse files
committed
U317-021 remove big amount of concatenations
... in lsp-predefined_completion-ada2012.ads, in order to help LAL process the project.
1 parent 8c58740 commit 338cc01

File tree

2 files changed

+1354
-1278
lines changed

2 files changed

+1354
-1278
lines changed

scripts/predefined_completion.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,44 @@
5858
end LSP.Predefined_Completion.%s;
5959
"""
6060

61+
MAX_LINES_PER_BIT = 50
62+
63+
6164
def convert_to_ada(json_filename, output_file):
6265
"""
6366
Convert the JSON file content into an hard-coded Ada string that
6467
will contain it.
6568
"""
69+
70+
line_counter = 0
71+
statement_counter = 1
6672
with open(json_filename, "r") as json_file:
6773
output = ""
6874

69-
output = ' Db : constant String := '
7075
for line in json_file.readlines():
71-
output += '"' + line.strip().replace('"', '""') + \
72-
'" & ASCII.LF\n & '
76+
if line_counter % MAX_LINES_PER_BIT == 0:
77+
if statement_counter != 1:
78+
output = output[:-6] + ";"
79+
output += f"\n\n Db{statement_counter} : constant String := "
80+
statement_counter += 1
81+
82+
output += '"' + line.strip().replace('"', '""') + '" & ASCII.LF\n & '
83+
84+
line_counter += 1
85+
86+
output = (
87+
output[:-6]
88+
+ f';\n\n Db : constant String := {" & ".join([f"Db{x}" for x in range(1, statement_counter)])};'
89+
)
7390

74-
output = output[:-6] + ';'
7591
output_file.write(output)
7692

93+
7794
json_filename = sys.argv[1]
7895
ada_version = os.path.basename(json_filename).replace(".json", "")
79-
ads_filename = "source/ada/generated/lsp-predefined_completion-%s.ads" \
80-
% ada_version
96+
ads_filename = "source/ada/generated/lsp-predefined_completion-%s.ads" % ada_version
8197

82-
ads = open(ads_filename, "wb")
98+
ads = open(ads_filename, "w")
8399
ads.write(spec_header % ada_version.title())
84100
convert_to_ada(json_filename, ads)
85101
ads.write(spec_footer % ada_version.title())

0 commit comments

Comments
 (0)