|
58 | 58 | end LSP.Predefined_Completion.%s;
|
59 | 59 | """
|
60 | 60 |
|
| 61 | +MAX_LINES_PER_BIT = 50 |
| 62 | + |
| 63 | + |
61 | 64 | def convert_to_ada(json_filename, output_file):
|
62 | 65 | """
|
63 | 66 | Convert the JSON file content into an hard-coded Ada string that
|
64 | 67 | will contain it.
|
65 | 68 | """
|
| 69 | + |
| 70 | + line_counter = 0 |
| 71 | + statement_counter = 1 |
66 | 72 | with open(json_filename, "r") as json_file:
|
67 | 73 | output = ""
|
68 | 74 |
|
69 |
| - output = ' Db : constant String := ' |
70 | 75 | 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 | + ) |
73 | 90 |
|
74 |
| - output = output[:-6] + ';' |
75 | 91 | output_file.write(output)
|
76 | 92 |
|
| 93 | + |
77 | 94 | json_filename = sys.argv[1]
|
78 | 95 | 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 |
81 | 97 |
|
82 |
| -ads = open(ads_filename, "wb") |
| 98 | +ads = open(ads_filename, "w") |
83 | 99 | ads.write(spec_header % ada_version.title())
|
84 | 100 | convert_to_ada(json_filename, ads)
|
85 | 101 | ads.write(spec_footer % ada_version.title())
|
0 commit comments