Reason: refmt changes the representation of integers

Created on 21 May 2016  路  4Comments  路  Source: reasonml/reason

The following code in OCaml
let x = 0x7FFFFFF ;;
becomes after converting it
let x = 134217727;
it would be good keeping the original representation.

Most helpful comment

Wait until Reason is based on OCaml 4.03, the Ast now contains integer as string. see https://github.com/ocaml/ocaml/blob/trunk/parsing/parsetree.mli#L20

All 4 comments

hmm, not sure how to fix it as the AST generated by the two integer literals are identical. (see attached screenshot)

image

One thing that can fix it from Reason side is to attached a ppx attribute when we parse it, so 0xF will be parsed as something like 15 [@base 16]. In printing time, we can print it accordingly.

Wait until Reason is based on OCaml 4.03, the Ast now contains integer as string. see https://github.com/ocaml/ocaml/blob/trunk/parsing/parsetree.mli#L20

@hhugo Niiiiice!

If this does come up again in the future for various AST nodes which have dual representation, a way to resolve it pretty easily, is to store an attribute on that node recording which of the representations was parsed, and then use that when printing it back out (of course, filtering out those actual attributes when printing).

Was this page helpful?
0 / 5 - 0 ratings