Skip to content

Commit

Permalink
Merge pull request #323 from jindraivanek/tuple-unify
Browse files Browse the repository at this point in the history
Unify genExpr code for tuples and struct tuples.
  • Loading branch information
nojaf authored Oct 12, 2018
2 parents 5b9a804 + 4f8cf44 commit eec36d3
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) ->
Expand Down

0 comments on commit eec36d3

Please sign in to comment.