diff --git a/src/Language/Cimple/Parser.y b/src/Language/Cimple/Parser.y index 965e1f4..40b668c 100644 --- a/src/Language/Cimple/Parser.y +++ b/src/Language/Cimple/Parser.y @@ -659,7 +659,7 @@ MemberDecl :: { NonTerm } MemberDecl : VarDecl ';' { Fix $ MemberDecl $1 Nothing } | VarDecl ':' LIT_INTEGER ';' { Fix $ MemberDecl $1 (Just $3) } -| PreprocIfdef(MemberDeclList) { $1 } +| PreprocIfdef(MemberDecls) { $1 } | Comment { $1 } TypedefDecl :: { NonTerm } diff --git a/test/Language/Cimple/PrettySpec.hs b/test/Language/Cimple/PrettySpec.hs index f3fe0a5..dffe804 100644 --- a/test/Language/Cimple/PrettySpec.hs +++ b/test/Language/Cimple/PrettySpec.hs @@ -89,6 +89,27 @@ spec = do , "} Foo;" ] + it "pretty-prints ifdef'd struct members in the correct order" $ + compact (unlines + [ "typedef struct Foo {" + , " int32_t a;" + , "#ifdef ENABLE_XY" + , " int32_t x;" + , " int32_t y;" + , "#endif /* ENABLE_XY */" + , "} Foo;" + ]) + `shouldBe` unlines + [ "typedef struct Foo {" + , "int32_t a;" + , "#ifdef ENABLE_XY" + , "int32_t x;" + , "" + , "int32_t y;" + , "#endif /* ENABLE_XY */" + , "} Foo;" + ] + it "respects newlines at end of comments" $ do compact "/* foo bar */" `shouldBe` "/* foo bar */\n" compact "/* foo bar\n */" `shouldBe` "/* foo bar\n */\n"