diff --git a/src/Language/Fortran/Parser/Fixed/Fortran77.y b/src/Language/Fortran/Parser/Fixed/Fortran77.y index 1abca141..420dc69e 100644 --- a/src/Language/Fortran/Parser/Fixed/Fortran77.y +++ b/src/Language/Fortran/Parser/Fixed/Fortran77.y @@ -606,9 +606,12 @@ POINTER_LIST :: { [ Declarator A0 ] } : POINTER_LIST ',' POINTER { $3 : $1 } | POINTER { [ $1 ] } +-- Cray pointers as of https://gcc.gnu.org/onlinedocs/gfortran/Cray-pointers.html POINTER :: { Declarator A0 } -: '(' VARIABLE ',' VARIABLE ')' - { Declarator () (getTransSpan $1 $5) $2 ScalarDecl Nothing (Just $4) } +: '(' VARIABLE ',' VARIABLE '(' DIMENSION_DECLARATORS ')' ')' + { Declarator () (getTransSpan $1 $8) $4 (ArrayDecl (aReverse $6)) Nothing (Just $2) } +| '(' VARIABLE ',' VARIABLE ')' + { Declarator () (getTransSpan $1 $5) $4 ScalarDecl Nothing (Just $2) } COMMON_GROUPS :: { AList CommonGroup A0 } : COMMON_GROUPS COMMON_GROUP { setSpan (getTransSpan $1 $2) $ $2 `aCons` $1 } diff --git a/test/Language/Fortran/Parser/Fixed/Fortran77/ParserSpec.hs b/test/Language/Fortran/Parser/Fixed/Fortran77/ParserSpec.hs index 0e709a2d..630be494 100644 --- a/test/Language/Fortran/Parser/Fixed/Fortran77/ParserSpec.hs +++ b/test/Language/Fortran/Parser/Fixed/Fortran77/ParserSpec.hs @@ -387,6 +387,20 @@ spec = resetSrcSpan (slParser autoSrc) `shouldBe` autoStmt resetSrcSpan (slParser staticSrc) `shouldBe` staticStmt + describe "Cray Pointer Extension" $ do + it "parses simple pointee decleration" $ do + let pointerStmt = StPointer () u (AList () u [p]) + p = Declarator () u (varGen "y") ScalarDecl Nothing (Just (varGen "x")) + pointerSrc = " pointer (x, y)" + resetSrcSpan (slParser pointerSrc) `shouldBe` pointerStmt + it "parses array pointee decleration" $ do + let pointerStmt = StPointer () u (AList () u [p]) + p = Declarator () u (varGen "y") arrayDecl Nothing (Just (varGen "x")) + arrayDecl = ArrayDecl (AList () u [dim]) + dim = DimensionDeclarator () u Nothing (Just $ intGen 3) + pointerSrc = " pointer (x, y(3))" + resetSrcSpan (slParser pointerSrc) `shouldBe` pointerStmt + exampleProgram1 :: String exampleProgram1 = unlines [ " program hello"