From 4661cfdb78df142c8d29bfec3dbc5fe37226f064 Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Fri, 29 Nov 2024 15:55:14 +0300 Subject: [PATCH] fix(eo-phi-normalizer): handle trailing comma the same way in more cases --- .../src/Language/EO/Phi/Syntax.hs | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Syntax.hs b/eo-phi-normalizer/src/Language/EO/Phi/Syntax.hs index 498fe50b..bd130a42 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Syntax.hs +++ b/eo-phi-normalizer/src/Language/EO/Phi/Syntax.hs @@ -63,13 +63,8 @@ render d = rend 0 False (map ($ "") $ d []) "" ShowS rend i p = \case "[" : "]" : ts -> showString "[]" . rend i False ts - "(" : ")" : (t : ts) -> - (pending . showString "()") - . ( case t of - "," -> showChar ',' . new i ts - _ -> rend i False (t : ts) - ) - "⟦" : "⟧" : ts -> showString "⟦ ⟧" . rend i False ts + "(" : ")" : (t : ts) -> handleTrailingComma "()" t ts + "⟦" : "⟧" : (t : ts) -> handleTrailingComma "⟦ ⟧" t ts "[" : ts -> char '[' . rend i False ts "(" : ts -> char '(' . new (i + 1) ts "{" : "⟦" : ts -> showChar '{' . onNewLine (i + 1) p . showChar '⟦' . new (i + 2) ts @@ -82,13 +77,7 @@ render d = rend 0 False (map ($ "") $ d []) "" [";"] -> char ';' ";" : ts -> char ';' . new i ts "." : ts -> rend i p (" ." : ts) - t : ts@(s : ss) - | closingOrPunctuation s -> - (pending . showString t) - . ( case s of - "," -> showChar ',' . new i ss - _ -> rend i False ts - ) + t : (s : ss) | closingOrPunctuation s -> handleTrailingComma t s ss t : ts -> pending . space t . rend i False ts [] -> id where @@ -96,6 +85,13 @@ render d = rend 0 False (map ($ "") $ d []) "" char :: Char -> ShowS char c = pending . showChar c + handleTrailingComma str t ts = + (pending . showString str) + . ( case t of + "," -> showChar ',' . new i ts + _ -> rend i False (t : ts) + ) + -- Output pending indentation. pending :: ShowS pending = if p then indent i else id