From 4f8cf4447a841c75e99db32a5d6db15635ab0dba Mon Sep 17 00:00:00 2001 From: jindraivanek Date: Fri, 12 Oct 2018 09:12:27 +0200 Subject: [PATCH] Unify genExpr code for tuples and struct tuples. --- src/Fantomas/CodePrinter.fs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 85c90c5014..526c91d375 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -466,6 +466,12 @@ and genVal astContext (Val(ats, px, ao, s, t, vi, _)) = and genRecordFieldName astContext (RecordFieldName(s, eo)) = opt sepNone eo (fun e -> !- s +> sepEq +> preserveBreakNlnOrAddSpace astContext e) +and genTuple astContext es = + atCurrentColumn (coli sepComma es (fun i -> + if i = 0 then genExpr astContext else noIndentBreakNln astContext + |> addParenWhen (function |ElIf _ -> true |_ -> false) // "if .. then .. else" have precedence over "," + )) + and genExpr astContext = function | SingleExpr(kind, e) -> str kind +> genExpr astContext e | ConstExpr(c) -> genConst c @@ -480,15 +486,8 @@ and genExpr astContext = function | TypedExpr(Downcast, e, t) -> genExpr astContext e -- " :?> " +> genType astContext false t | TypedExpr(Upcast, e, t) -> genExpr astContext e -- " :> " +> genType astContext false t | TypedExpr(Typed, e, t) -> genExpr astContext e +> sepColon +> genType astContext false t - | StructTuple es -> - !- "struct " +> sepOpenT +> - atCurrentColumn (coli sepComma es (fun i -> if i = 0 then genExpr astContext else noIndentBreakNln astContext)) - +> sepCloseT - | Tuple es -> - atCurrentColumn (coli sepComma es (fun i -> - if i = 0 then genExpr astContext else noIndentBreakNln astContext - |> addParenWhen (function |ElIf _ -> true |_ -> false) // "if .. then .. else" have precedence over "," - )) + | Tuple es -> genTuple astContext es + | StructTuple es -> !- "struct " +> sepOpenT +> genTuple astContext es +> sepCloseT | ArrayOrList(isArray, [], _) -> ifElse isArray (sepOpenAFixed +> sepCloseAFixed) (sepOpenLFixed +> sepCloseLFixed) | ArrayOrList(isArray, xs, isSimple) ->