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

Weird annotations for comments #75

Open
mrkkrp opened this issue Mar 4, 2019 · 1 comment
Open

Weird annotations for comments #75

mrkkrp opened this issue Mar 4, 2019 · 1 comment

Comments

@mrkkrp
Copy link

mrkkrp commented Mar 4, 2019

If we parse this input:

import qualified MegaModule as M
  ( (>>>) -- (1)
  , (<<<) -- (2)
  , Either -- (3)
  )

-- (1) appears in annotations for (>>>), -- (2) appears in annotations for (<<<), but -- (3) is attached to some weird thingy:

[(AnnKey Foo.hs:1:1 CN "HsModule",
  (Ann (DP (0,0)) [] [] [((G AnnEofPos),DP (1,0))] Nothing Nothing)),
 (AnnKey Foo.hs:(1,1)-(5,3) CN "ImportDecl",
  (Ann (DP (0,0)) [] [] [((G AnnImport),DP (0,0)),((G AnnQualified),DP (0,1)),((G AnnAs),DP (0,1))] Nothing Nothing)),
 (AnnKey Foo.hs:1:18-27 CN "{abstract:ModuleName}",
  (Ann (DP (0,1)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing)),
 (AnnKey Foo.hs:1:32 CN "{abstract:ModuleName}",
  (Ann (DP (0,1)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing)),
 (AnnKey Foo.hs:(2,3)-(5,3) CN "(:)",
  (Ann (DP (1,2)) [] [] [((G AnnOpenP),DP (0,0)),((AnnComment (Comment "-- (3)" Foo.hs:4:12-17 Nothing)),DP (0,1)),((G AnnCloseP),DP (1,2))] Nothing Nothing)),
 (AnnKey Foo.hs:2:5-9 CN "IEName",
  (Ann (DP (0,0)) [] [] [] Nothing Nothing)),
 (AnnKey Foo.hs:2:5-9 CN "IEVar",
  (Ann (DP (0,1)) [] [] [((AnnComment (Comment "-- (1)" Foo.hs:2:11-16 Nothing)),DP (0,1)),((G AnnComma),DP (1,2))] Nothing Nothing)),
 (AnnKey Foo.hs:2:5-9 CN "Unqual",
  (Ann (DP (0,0)) [] [] [((G AnnOpenP),DP (0,0)),((G AnnVal),DP (0,0)),((G AnnCloseP),DP (0,0))] Nothing Nothing)),
 (AnnKey Foo.hs:3:5-9 CN "IEName",
  (Ann (DP (0,0)) [] [] [] Nothing Nothing)),
 (AnnKey Foo.hs:3:5-9 CN "IEVar",
  (Ann (DP (0,1)) [] [] [((AnnComment (Comment "-- (2)" Foo.hs:3:11-16 Nothing)),DP (0,1)),((G AnnComma),DP (1,2))] Nothing Nothing)),
 (AnnKey Foo.hs:3:5-9 CN "Unqual",
  (Ann (DP (0,0)) [] [] [((G AnnOpenP),DP (0,0)),((G AnnVal),DP (0,0)),((G AnnCloseP),DP (0,0))] Nothing Nothing)),
 (AnnKey Foo.hs:4:5-10 CN "IEName",
  (Ann (DP (0,0)) [] [] [] Nothing Nothing)),
 (AnnKey Foo.hs:4:5-10 CN "IEThingAbs",
  (Ann (DP (0,1)) [] [] [] Nothing Nothing)),
 (AnnKey Foo.hs:4:5-10 CN "Unqual",
  (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing))]

What on the earth is this "(:)" and why the last comment is treated specially?

@lspitzner
Copy link
Contributor

Using brittany --dump-ast-full explains the "(:)", as it yields

---- ast ----
A Just (Ann (DP (0,0)) [] [] [((G AnnEofPos),DP (1,0))] Nothing Nothing)
  HsModule
    Nothing
    Nothing
    [ A Just (Ann (DP (0,0)) [] [] [((G AnnImport),DP (0,0)),((G AnnQualified),DP (0,1)),((G AnnAs),DP (0,1))] Nothing Nothing)
        ImportDecl
          NoExt
          NoSourceText
          A Just (Ann (DP (0,1)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing)
            {abstract:ModuleName}
          Nothing
          False
          False
          True
          False
          Just
            A Just (Ann (DP (0,1)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing)
              {abstract:ModuleName}
          Just
            (,)
              False
              A Just (Ann (DP (1,2)) [] [] [((G AnnOpenP),DP (0,0)),((AnnComment (Comment "-- (3)" stdin:4:12-17 Nothing)),DP (0,1)),((G AnnCloseP),DP (1,2))] Nothing Nothing)
                [ A Just (Ann (DP (0,1)) [] [] [((AnnComment (Comment "-- (1)" stdin:2:11-16 Nothing)),DP (0,1)),((G AnnComma),DP (1,2))] Nothing Nothing)
                    IEVar
                      NoExt
                      A Just (Ann (DP (0,0)) [] [] [] Nothing Nothing)
                        IEName
                          A Just (Ann (DP (0,0)) [] [] [((G AnnOpenP),DP (0,0)),((G AnnVal),DP (0,0)),((G AnnCloseP),DP (0,0))] Nothing Nothing)
                            Unqual {OccName: >>>}
                , A Just (Ann (DP (0,1)) [] [] [((AnnComment (Comment "-- (2)" stdin:3:11-16 Nothing)),DP (0,1)),((G AnnComma),DP (1,2))] Nothing Nothing)
                    IEVar
                      NoExt
                      A Just (Ann (DP (0,0)) [] [] [] Nothing Nothing)
                        IEName
                          A Just (Ann (DP (0,0)) [] [] [((G AnnOpenP),DP (0,0)),((G AnnVal),DP (0,0)),((G AnnCloseP),DP (0,0))] Nothing Nothing)
                            Unqual {OccName: <<<}
                , A Just (Ann (DP (0,1)) [] [] [] Nothing Nothing)
                    IEThingAbs
                      NoExt
                      A Just (Ann (DP (0,0)) [] [] [] Nothing Nothing)
                        IEName
                          A Just (Ann (DP (0,0)) [] [] [((G AnnVal),DP (0,0))] Nothing Nothing)
                            Unqual {OccName: Either}
                ]
    ]
    []
    Nothing
    Nothing
----

I.e. it is connected to the list of import items. Quite similar to #77 where the last comment is connected to the surrounding construct instead of the last contained item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants