From 61daedbd3c6b05f4de17d782de0f9565582fcb9c Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 23 Jan 2024 21:53:05 +0000 Subject: [PATCH] fix: Fix pretty-printer to output correct `#endif` comments. --- src/Language/Cimple/Lexer.x | 1 + src/Language/Cimple/Pretty.hs | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Language/Cimple/Lexer.x b/src/Language/Cimple/Lexer.x index 51d1550..c2311f1 100644 --- a/src/Language/Cimple/Lexer.x +++ b/src/Language/Cimple/Lexer.x @@ -192,6 +192,7 @@ tokens :- <0,ppSC> "false" { mkL LitFalse } <0,ppSC> "true" { mkL LitTrue } <0,ppSC> "__func__" { mkL IdVar } +<0,ppSC> "nullptr" { mkL IdConst } <0,ppSC> "__"[a-zA-Z]+"__"? { mkL IdConst } <0,ppSC> [A-Z][A-Z0-9_]{1,2} { mkL IdSueType } <0,ppSC> _*[A-Z][A-Z0-9_]* { mkL IdConst } diff --git a/src/Language/Cimple/Pretty.hs b/src/Language/Cimple/Pretty.hs index d1b9e14..037e422 100644 --- a/src/Language/Cimple/Pretty.hs +++ b/src/Language/Cimple/Pretty.hs @@ -417,7 +417,7 @@ ppNode = foldFix go ppToplevel decls <$> line <> dullmagenta (text "#ifdef __cplusplus") <$> - rbrace <$> + rbrace <+> text "/* extern \"C\" */" <$> dullmagenta (text "#endif") Group decls -> vcat decls @@ -446,17 +446,17 @@ ppNode = foldFix go dullmagenta (text "#if" <+> cond) <$> ppToplevel decls <> elseBranch <$> - dullmagenta (text "#endif") + dullmagenta (text "#endif /*" <+> cond <+> text "*/") PreprocIfdef name decls elseBranch -> dullmagenta (text "#ifdef" <+> ppLexeme name) <$> ppToplevel decls <> elseBranch <$> - dullmagenta (text "#endif //" <+> ppLexeme name) + dullmagenta (text "#endif /*" <+> ppLexeme name <+> text "*/") PreprocIfndef name decls elseBranch -> dullmagenta (text "#ifndef" <+> ppLexeme name) <$> ppToplevel decls <> elseBranch <$> - dullmagenta (text "#endif //" <+> ppLexeme name) + dullmagenta (text "#endif /*" <+> ppLexeme name <+> text "*/") PreprocElse [] -> empty PreprocElse decls -> linebreak <>