Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix pretty-printer to output correct #endif comments. #106

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Language/Cimple/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
8 changes: 4 additions & 4 deletions src/Language/Cimple/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
UnaryOp (..), lexemeLine,
lexemeText)
import Prelude hiding ((<$>))
import Text.PrettyPrint.ANSI.Leijen

Check warning on line 25 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

Module ‘Text.PrettyPrint.ANSI.Leijen’ is deprecated:

indentWidth :: Int
indentWidth = 2

kwBreak = dullred $ text "break"

Check warning on line 30 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘dullred’

Check warning on line 30 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘text’ (imported from Text.PrettyPrint.ANSI.Leijen):
kwCase = dullred $ text "case"

Check warning on line 31 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘dullred’

Check warning on line 31 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘text’ (imported from Text.PrettyPrint.ANSI.Leijen):
kwConst = dullgreen $ text "const"

Check warning on line 32 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘dullgreen’

Check warning on line 32 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘text’ (imported from Text.PrettyPrint.ANSI.Leijen):
kwContinue = dullred $ text "continue"

Check warning on line 33 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘dullred’

Check warning on line 33 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘text’ (imported from Text.PrettyPrint.ANSI.Leijen):
kwDefault = dullred $ text "default"

Check warning on line 34 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘dullred’
kwDo = dullred $ text "do"
kwElse = dullred $ text "else"
kwEnum = dullgreen $ text "enum"
Expand Down Expand Up @@ -417,7 +417,7 @@
ppToplevel decls <$>
line <>
dullmagenta (text "#ifdef __cplusplus") <$>
rbrace <$>
rbrace <+> text "/* extern \"C\" */" <$>
dullmagenta (text "#endif")

Group decls -> vcat decls
Expand Down Expand Up @@ -446,17 +446,17 @@
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 <>
Expand Down