x-heep icon indicating copy to clipboard operation
x-heep copied to clipboard

Remove trailing commas in hjson files

Open cousteaulecommandant opened this issue 7 months ago • 1 comments

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 avatar Jul 12 '24 17:07 cousteaulecommandant