leostera / caramel

:candy: a functional language for building type-safe, scalable, and maintainable applications
https://caramel.run
Apache License 2.0
1.06k stars 25 forks source link

fix: Support OCaml style floating point syntax without trailing numbers after dot #61

Closed michallepicki closed 3 years ago

michallepicki commented 3 years ago

closes #55

(not sure if changing the erl_printer is the correct fix so I'm happy to change if it's not)

michallepicki commented 3 years ago

~Hmm I think this adds a 0 when it's not necessary as well. I'll fix it sometime but~ (edit: fixed) the question whether this is the correct place to fix it is still valid :)

michallepicki commented 3 years ago

Alternatively I could fix this here I think ?

leostera commented 3 years ago

@michallepicki yes! the second place feels a lot cleaner since its where all the OCaml->Erlang specific conversions are made. The printer should just assume the Erlang AST is valid.

Additionally, we could add a Erlang.Ast_helpers.Const.float_of_string function to do this parsing.

michallepicki commented 3 years ago

@ostera There's this helper already: https://github.com/AbstractMachinesLab/caramel/blob/main/erlang/src/erl_ast_helper.ml#L54 - should I modify it instead of adding a new function? It is already being called in the Fun module linked before ( https://github.com/AbstractMachinesLab/caramel/blob/main/caramel/compiler/ocaml_to_erlang/fun.ml#L14 )

leostera commented 3 years ago

@michallepicki yup! I think we can use that one as well.

One last alternative would be to start implementing the AST invariants module to return an error if the float's are wrong.

Like, the OCaml_to_Erlang module should be responsible of formatting the floats right, the AST modules should help you verify that it is indeed right.

michallepicki commented 3 years ago

@ostera I cannot request a review on the PR but it should be ready to go once CI passes. I added a small test for this kind of float literals.