x-heep
x-heep copied to clipboard
Hjson: quoteless strings shall not include a comma (#552)
Some hjson files in X-HEEP use trailing comma after a "quoteless string" which isn't valid in the standard (https://hjson.github.io/syntax.html):
Do not add commas or comments as they would become part of the string.
This includes "barewords" such as active: low,
but also (surprisingly) hexadecimal values such as address: 0x10000000,
which is technically also interpreted as a string and not an integer value. So if you add a comma there, the hjson parser considers it as part of the string (this is not a bug in the parser, it's the correct interpretation of the file).
Commas are fine (but superfluous) if the string is quoted, and also after numbers, true
, and false
.
This was reported as #552, which this PR fixes.
This fix also deprecates certain workarounds in the code that were using .split(',')
or .strip(',')
to address this issue (but the issue was really that the file format was wrong, not that the parser failed).
I decided not to remove those fixes from mcu_gen.py
just in case, but in principle they're no longer necessary if files are kept consistent with the Hjson format.
It would probably be a good idea to get rid of commas in hjson files entirely (including after numbers, quoted strings, or closing brackets/braces), since they are superfluous and the standard discourages its use, but I decided to leave that out of this PR as well.