@@ -254,7 +254,7 @@ let needs_grouping = (~parent, ~side: infix_side, expr) => {
254254 } else {
255255 FormatterGrouping ;
256256 }
257- | (PExpConstant (PConstNumber (PConstNumberRational (_, _ ))), _)
257+ | (PExpConstant (PConstNumber (PConstNumberRational (_))), _)
258258 when op_precedence('/' ) <= precedence(parent) =>
259259 ParenGrouping
260260 | _ => FormatterGrouping
@@ -314,8 +314,43 @@ let build_document = (~original_source, parsed_program) => {
314314 | _ => failwith ("Impossible: non- prefix or infix op" )
315315 };
316316 }
317- and print_constant = (~loc, constant) => {
318- string(get_original_code(loc));
317+ and print_constant = constant => {
318+ switch (constant) {
319+ | PConstNumber (PConstNumberInt ({txt: value })) => string(value)
320+ | PConstNumber (PConstNumberFloat ({txt: value })) => string(value)
321+ | PConstNumber (PConstNumberRational ({numerator, slash, denominator})) =>
322+ string(numerator. txt)
323+ ++ print_comment_range(~lead= space, ~trail= space, numerator. loc, slash)
324+ ++ string("/" )
325+ ++ print_comment_range(
326+ ~lead= space,
327+ ~trail= space,
328+ slash,
329+ denominator. loc,
330+ )
331+ ++ string(denominator. txt)
332+ | PConstInt8 ({txt: value })
333+ | PConstUint8 ({txt: value })
334+ | PConstInt16 ({txt: value })
335+ | PConstUint16 ({txt: value })
336+ | PConstInt32 ({txt: value })
337+ | PConstUint32 ({txt: value })
338+ | PConstInt64 ({txt: value })
339+ | PConstUint64 ({txt: value })
340+ | PConstFloat32 ({txt: value })
341+ | PConstFloat64 ({txt: value })
342+ | PConstWasmI32 ({txt: value })
343+ | PConstWasmI64 ({txt: value })
344+ | PConstWasmF32 ({txt: value })
345+ | PConstWasmF64 ({txt: value })
346+ | PConstBigInt ({txt: value })
347+ | PConstRational ({txt: value })
348+ | PConstBytes ({txt: value })
349+ | PConstString ({txt: value })
350+ | PConstChar ({txt: value }) => string(value)
351+ | PConstBool (value ) => string(value ? "true" : "false" )
352+ | PConstVoid => string("void" )
353+ };
319354 }
320355 and print_punnable_pattern =
321356 (
@@ -508,7 +543,7 @@ let build_document = (~original_source, parsed_program) => {
508543 typ. ptyp_loc,
509544 )
510545 ++ print_type(typ)
511- | PPatConstant (constant ) => print_constant(~loc = ppat_loc , constant)
546+ | PPatConstant (constant ) => print_constant(constant)
512547 | PPatRecord (pats , closed_flag ) =>
513548 braces(
514549 indent(
@@ -1222,8 +1257,7 @@ let build_document = (~original_source, parsed_program) => {
12221257 ++ (
12231258 switch (expr. pexp_desc) {
12241259 | PExpId ({txt: ident }) => print_identifier(ident)
1225- | PExpConstant (constant ) =>
1226- print_constant(~loc= expr. pexp_loc, constant)
1260+ | PExpConstant (constant ) => print_constant(constant)
12271261 | PExpConstruct ({txt: ident , loc: ident_loc }, cstr_expr ) =>
12281262 print_identifier(ident)
12291263 ++ (
0 commit comments