Skip to content

Commit

Permalink
fix(eo-phi-normalizer): handle trailing comma the same way in more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Nov 29, 2024
1 parent d5b7e00 commit 4661cfd
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions eo-phi-normalizer/src/Language/EO/Phi/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -82,20 +77,21 @@ 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
-- Output character after pending indentation.
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
Expand Down

0 comments on commit 4661cfd

Please sign in to comment.