iets3.opensource icon indicating copy to clipboard operation
iets3.opensource copied to clipboard

core.expr: implement hex numbers

Open alexanderpann opened this issue 1 year ago • 1 comments

This is a more editor-heavy reimplementation of https://github.com/IETS3/iets3.opensource/pull/630 that is hopefully is not a breaking change anymore. There is only a small issue that when you create a hex value in the max field in the range specs the cursor jumps to the min field afterwards. I couldn't fix this issue but it is only a small inconvenience. See previous PR for a screenshot. The approach can be adapted for any string properties that are used for storing numbers.

Changes:

  • Number literals, collection size specifications and number range specifications now support entering numbers in hexadecimal format. This feature can be deactived through PrimitiveTypeMapper#allowHexadecimalNumbers.
  • Collection size and number range specifications now initialize with an infinite range by default. Setting the min and max field therefore is equal to setting them to infinity.

alexanderpann avatar Sep 26 '24 12:09 alexanderpann

How will this feature work with migrations?

When you set node.value you lose the hex value. I introduced a new method to also set the hex value. Example: node.updateHexValueOrProperty(property/NumberLiteral : value/, "100")

Using Hex-values is not propagated

Fixed.

Can we make auto-completion also work when someone enters only the string

I implemented it so that 0x0 is automatically inserted but that also feels awkward. Should we generate a new hex value with invalid value "" instead? If the user enters 0x the editor cell is red and he has to enter a value.

What direction do we want to enforce by default?

According to the internet, the evaluation from right to left as implemented here seems to be the standard. You can try it with different tools e.g. enter "0x0f in decimal" on Google.

Is there a possibility to automatically remove the hex-value?

The easiest way to remove it, is to write node.value = node.value

Can we per default switch this feature off

Done.

alexanderpann avatar Oct 07 '24 12:10 alexanderpann

@HeikoBecker Thanks for noticing. I fixed both issues.

alexanderpann avatar Oct 14 '24 06:10 alexanderpann

@alexanderpann I think your merge went sideways. It looks like parts of the fixes introduced in commit a93b766a were removed/overriden. Could you please double check?

It is no longer possible to create hex value representations for min range of NumberRangeSpec and max range of CollectionSizeSpec. Also NumberLiterals are not supporting hex notation either.

arimer avatar Oct 15 '24 08:10 arimer