@@ -412,7 +412,17 @@ p_hsLocalBinds = \case
412 (Left <$> bagToList bag) ++ (Right <$> lsigs)
412 (Left <$> bagToList bag) ++ (Right <$> lsigs)
413 p_item (Left x) = located x p_valDecl
413 p_item (Left x) = located x p_valDecl
414 p_item (Right x) = located x p_sigDecl
414 p_item (Right x) = located x p_sigDecl
415+ -- Assigns 'False' to the last element, 'True' to the rest.
416+ markInit :: [a] -> [(Bool, a)]
418+ markInit (x:[]) = [(False, x)]
419+ markInit (x:xs) = (True, x) : markInit xs
420+ -- NOTE When in a single-line layout, there is a chance that the inner
421+ -- elements will also contain semicolons and they will confuse the
422+ -- parser. so we request braces around every element except the last.
424+ (\(m, i) -> (if m then useBraces else id) $ p_item i)
415− sitcc $ sepSemi (useBraces . p_item) (sortOn ssStart items)
425+ (markInit $ sortOn ssStart items)
416 HsValBinds NoExt _ -> notImplemented "HsValBinds"
426 HsValBinds NoExt _ -> notImplemented "HsValBinds"
417 HsIPBinds NoExt (IPBinds NoExt xs) ->
427 HsIPBinds NoExt (IPBinds NoExt xs) ->
418 -- Second argument of IPBind is always Left before type-checking.
428 -- Second argument of IPBind is always Left before type-checking.
@@ -420,7 +430,7 @@ p_hsLocalBinds = \case
420 atom name
430 atom name
422 breakpoint
432 breakpoint
423− dontUseBraces $ inci $ located expr p_hsExpr
433+ useBraces $ inci $ located expr p_hsExpr
424 p_ipBind _ = notImplemented "XHsIPBinds"
434 p_ipBind _ = notImplemented "XHsIPBinds"
425 in sepSemi (located' p_ipBind) xs
435 in sepSemi (located' p_ipBind) xs
426 HsIPBinds NoExt _ -> notImplemented "HsIpBinds"
436 HsIPBinds NoExt _ -> notImplemented "HsIpBinds"
@@ -553,7 +563,7 @@ p_hsExpr = \case
553 inci . sitcc $ sep newline (located' (p_grhs RightArrow)) guards
563 inci . sitcc $ sep newline (located' (p_grhs RightArrow)) guards
554 HsLet NoExt localBinds e -> do
564 HsLet NoExt localBinds e -> do
555 txt "let "
565 txt "let "
556− sitcc (located localBinds p_hsLocalBinds)
566+ dontUseBraces $ sitcc (located localBinds p_hsLocalBinds)
557 vlayout space (newline >> space)
567 vlayout space (newline >> space)
558 txt "in "
568 txt "in "
559 sitcc (located e p_hsExpr)
569 sitcc (located e p_hsExpr)