@@ -7,6 +7,7 @@ import Language.Fortran.Version
77import Language.Fortran.AST
88
99import qualified Language.Fortran.Parser.Fortran90 as F90
10+ import qualified Language.Fortran.Parser.Fortran77 as F77
1011import qualified Language.Fortran.Parser.Fortran66 as F66
1112import qualified Language.Fortran.Lexer.FreeForm as LexFree
1213import qualified Language.Fortran.Lexer.FixedForm as LexFixed
@@ -23,10 +24,20 @@ main = defaultMain
2324 [ bench " statement (expr)" $ whnf pF90Stmt snippetFreeStmtExpr
2425 , bench " statement (assign)" $ whnf pF90Stmt snippetFreeStmtDeclAssign
2526 , bench " function" $ whnf pF90Func snippetFreeFunc
27+ , bench " ProgramFile (default transformations)" $ whnf pF90pfDefTs snippetFreePF
28+ , bench " ProgramFile (no transformations)" $ whnf pF90pfNoTs snippetFreePF
29+ ]
30+ , bgroup " Fortran 77"
31+ [ bench " statement (expr)" $ whnf pF77Stmt snippetFixedStmt
32+ -- , bench "function" $ whnf pF77Func snippetFixedFunc
33+ , bench " ProgramFile (default transformations)" $ whnf pF77pfDefTs snippetFixedPF
34+ , bench " ProgramFile (no transformations)" $ whnf pF77pfNoTs snippetFixedPF
2635 ]
2736 , bgroup " Fortran 66"
2837 [ bench " statement (expr)" $ whnf pF66Stmt snippetFixedStmt
29- , bench " function" $ whnf pF90Func snippetFixedFunc
38+ -- , bench "function" $ whnf pF66Func snippetFixedFunc
39+ -- , bench "ProgramFile (default transformations)" $ whnf pF66pfDefTs snippetFixedPF
40+ -- , bench "ProgramFile (no transformations)" $ whnf pF66pfNoTs snippetFixedPF
3041 ]
3142 ]
3243 ]
@@ -39,9 +50,45 @@ pF90Stmt = parseFree Fortran90 F90.statementParser
3950pF90Func :: ByteString -> ProgramUnit A0
4051pF90Func = parseFree Fortran90 F90. functionParser
4152
53+ pF90pfDefTs :: ByteString -> ProgramFile A0
54+ pF90pfDefTs = parseFull F90. fortran90Parser
55+
56+ pF90pfNoTs :: ByteString -> ProgramFile A0
57+ pF90pfNoTs = parseFull (F90. fortran90ParserWithTransforms [] )
58+
59+ pF77Stmt :: ByteString -> Statement A0
60+ pF77Stmt = parseFixed Fortran77 F77. statementParser
61+
62+ -- pF77Func :: ByteString -> ProgramUnit A0
63+ -- pF77Func = parseFixed Fortran77 F77.functionParser
64+
65+ pF77pfDefTs :: ByteString -> ProgramFile A0
66+ pF77pfDefTs = parseFull F77. fortran77Parser
67+
68+ pF77pfNoTs :: ByteString -> ProgramFile A0
69+ pF77pfNoTs = parseFull (F77. fortran77ParserWithTransforms [] )
70+
4271pF66Stmt :: ByteString -> Statement A0
4372pF66Stmt = parseFixed Fortran66 F66. statementParser
4473
74+ -- pF66Func :: ByteString -> Statement A0
75+ -- pF66Func = parseFixed Fortran66 F66.functionParser
76+
77+ pF66pfDefTs :: ByteString -> ProgramFile A0
78+ pF66pfDefTs = parseFull F66. fortran66Parser
79+
80+ pF66pfNoTs :: ByteString -> ProgramFile A0
81+ pF66pfNoTs = parseFull (F66. fortran66ParserWithTransforms [] )
82+
83+ -- polymorphic on lexer input+token in order to work with fixed & free form
84+ parseFull
85+ :: (ByteString -> String -> ParseResult alexin token (ProgramFile A0 ))
86+ -> ByteString -> ProgramFile A0
87+ parseFull parser bs =
88+ case parser bs " <unknown>" of
89+ ParseOk a _ -> a
90+ ParseFailed _ -> error " error"
91+
4592parseFree :: FortranVersion
4693 -> Parse LexFree. AlexInput LexFree. Token a -> ByteString -> a
4794parseFree ver parser src = evalParse parser parserState
@@ -72,6 +119,18 @@ snippetFreeFunc = programListing $
72119 , " end function f"
73120 ]
74121
122+ snippetFreePF :: ByteString
123+ snippetFreePF = programListing $
124+ [ " integer function f(x, y, z) result(i)"
125+ , " print *, i"
126+ , " i = (i - 1)"
127+ , " end function f"
128+ , " "
129+ , " program main"
130+ , " x = 1 + 2"
131+ , " end program main"
132+ ]
133+
75134--------------------------------------------------------------------------------
76135
77136snippetFixedStmt :: ByteString
@@ -87,6 +146,18 @@ snippetFixedFunc = programListing $
87146 , " end"
88147 ]
89148
149+ snippetFixedPF :: ByteString
150+ snippetFixedPF = programListing $
151+ [ " subroutine f(x, y, z)"
152+ , " print *, i"
153+ , " i = (i - 1)"
154+ , " end"
155+ , " "
156+ , " program main"
157+ , " x = 1 + 2"
158+ , " end"
159+ ]
160+
90161--------------------------------------------------------------------------------
91162
92163-- | unlines but without the trailing newline
@@ -95,13 +166,3 @@ programListing = strToByteString . intercalate "\n"
95166
96167strToByteString :: String -> ByteString
97168strToByteString = TSE. encodeUtf8 . Text. pack
98-
99- --------------------------------------------------------------------------------
100-
101- f90ProgramFile :: ByteString
102- f90ProgramFile = strToByteString $ intercalate " \n " $
103- [ " program main"
104- , " character(5) :: assign_in_decl*5 = \" test!\" "
105- , " assign_out_decl = \" test!\" "
106- , " end program main"
107- ]
0 commit comments