esl-epfl / x-heep

eXtendable Heterogeneous Energy-Efficient Platform based on RISC-V
Other
143 stars 78 forks source link

Remove trailing commas in hjson files #552

Open cousteaulecommandant opened 3 months ago

cousteaulecommandant commented 3 months ago

Hjson files should not contain commas at the end of each line. In particular, they MUST NOT in the case of "quoteless strings". However, the use of these commas is widespread in X-HEEP, which results in incorrect Hjson files.

Quoting the Hjson documentation:

Quoteless Strings

[...] Do not add commas or comments as they would become part of the string.

Furthermore (although less importantly):

Commas

[...] You should omit optional commas [other than for quoteless strings] to make your data more readable.

{
  one: 1
  two: 2
}

However, there are plenty of Hjson files in X-HEEP that use trailing commas, which in many cases are illegal since they will be included as part of the string. The most common cases are "barewords" and hex values starting with 0x (which are actually strings, not numbers):

active:  low,
address: 0x10000000,

But I would just remove all the trailing commas, since they're entirely optional (when they're allowed) and the standard itself recommends removing them. This includes trailing commas after a ], or a },.

This issue seems to have been "fixed" in some places of the Python code by explicitly adding .strip(','), but this is a workaround that "fixes the symptom" rather than fixing the broken file. This can be problematic in a future; I recommend fixing all the .hjson files so that they're compliant with Hjson in this regard.

cousteaulecommandant commented 3 months ago

I have created PR #553 to fix the affected hjson files, removing the commas that confuse the hjson parser (but leaving out other commas, although the standard recommends removing those as well). I have tried to be careful with the latest commit at main which also touched some of the affected hjson files (including a CI/CD-related file).