mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-19 16:28:12 +03:00
Move fix to lexer as suggested by @altgr
This commit is contained in:
parent
5ec91c7b00
commit
a52cc0d881
@ -197,21 +197,13 @@ let rec translate_expr
|
||||
decimal_of_string (i ^ "." ^ f) /& decimal_of_string "100"))
|
||||
| LBool b -> Desugared.Ast.ELit (Dcalc.Ast.LBool b)
|
||||
| LMoneyAmount i ->
|
||||
(* If the user has written $0.3 it means 30 cents so we have to pad
|
||||
with a 0 *)
|
||||
let reg = Re.compile (Re.seq [ Re.start; Re.digit; Re.stop ]) in
|
||||
let cents_correct =
|
||||
Re.replace reg
|
||||
~f:(fun group -> Re.Group.get group 0 ^ "0")
|
||||
i.money_amount_cents
|
||||
in
|
||||
Desugared.Ast.ELit
|
||||
(Dcalc.Ast.LMoney
|
||||
Runtime.(
|
||||
money_of_cents_integer
|
||||
(integer_of_string i.money_amount_units
|
||||
*! integer_of_int 100
|
||||
+! integer_of_string cents_correct)))
|
||||
+! integer_of_string i.money_amount_cents)))
|
||||
| LNumber ((Int i, _), Some (Year, _)) ->
|
||||
Desugared.Ast.ELit
|
||||
(Dcalc.Ast.LDuration
|
||||
|
@ -567,6 +567,9 @@ let rec lex_code (lexbuf : lexbuf) : token =
|
||||
| MC_DECIMAL_SEPARATOR -> buf := cents
|
||||
| _ -> ()
|
||||
done;
|
||||
(* If the user has written $0.3 it means 30 cents so we have to pad
|
||||
with a 0 *)
|
||||
Buffer.add_string cents (String.make (2 - Buffer.length cents) '0');
|
||||
L.update_acc lexbuf;
|
||||
MONEY_AMOUNT (Buffer.contents units, Buffer.contents cents)
|
||||
| Plus digit, MC_DECIMAL_SEPARATOR, Star digit ->
|
||||
|
Loading…
Reference in New Issue
Block a user