Skip to content

Commit

Permalink
New indented block after else in case of comment after else. Fix f…
Browse files Browse the repository at this point in the history
  • Loading branch information
jindraivanek committed May 7, 2018
1 parent 59e1c09 commit 10ff825
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,15 @@ and genExpr astContext = function
// It seems too annoying to use sepSemiNln
| Sequentials es -> atCurrentColumn (col sepNln es (genExpr astContext))
// A generalization of IfThenElse
| ElIf((e1,e2, _)::es, enOpt) ->
| ElIf((e1,e2, _,_)::es, enOpt) ->
atCurrentColumn (!- "if " +> ifElse (checkBreakForExpr e1) (genExpr astContext e1 ++ "then") (genExpr astContext e1 +- "then") -- " "
+> preserveBreakNln astContext e2
+> fun ctx -> col sepNone es (fun (e1, e2, r) ->
ifElse (startWith "elif" r ctx) (!+ "elif ") (!+ "else if ")
+> fun ctx -> col sepNone es (fun (e1, e2, r, fullRange) ->
let elsePart =
ifElse (ctx.Comments.ContainsKey fullRange.Start)
(!+ "else" +> indent +> sepNln -- "if ")
(!+ "else if ")
ifElse (startWith "elif" r ctx) (!+ "elif ") elsePart
+> ifElse (checkBreakForExpr e1) (genExpr astContext e1 ++ "then") (genExpr astContext e1 +- "then")
-- " " +> preserveBreakNln astContext e2) ctx
+> opt sepNone enOpt (fun en -> !+ "else " +> preserveBreakNln astContext en))
Expand Down
8 changes: 4 additions & 4 deletions src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,10 @@ let (|IfThenElse|_|) = function
| _ -> None

let rec (|ElIf|_|) = function
| SynExpr.IfThenElse(e1, e2, Some(ElIf(es, e3)), _, _, r, _) ->
Some((e1, e2, r)::es, e3)
| SynExpr.IfThenElse(e1, e2, e3, _, _, r, _) ->
Some([(e1, e2, r)], e3)
| SynExpr.IfThenElse(e1, e2, Some(ElIf(es, e3)), _, _, r, fullRange) ->
Some((e1, e2, r, fullRange)::es, e3)
| SynExpr.IfThenElse(e1, e2, e3, _, _, r, fullRange) ->
Some([(e1, e2, r, fullRange)], e3)
| _ -> None

let (|Record|_|) = function
Expand Down

0 comments on commit 10ff825

Please sign in to comment.