@@ -7,7 +7,9 @@ import Language.Fortran.Version
77import Language.Fortran.AST
88
99import qualified Language.Fortran.Parser.Fortran90 as F90
10+ import qualified Language.Fortran.Parser.Fortran66 as F66
1011import qualified Language.Fortran.Lexer.FreeForm as LexFree
12+ import qualified Language.Fortran.Lexer.FixedForm as LexFixed
1113
1214import Data.ByteString (ByteString )
1315import qualified Data.Text as Text
@@ -18,32 +20,52 @@ main :: IO ()
1820main = defaultMain
1921 [ bgroup " parser"
2022 [ bgroup " Fortran 90"
21- [ bench " statement (lone)" $ whnf pF90Stmt snippetFreeStmt
22- , bench " function (lone)" $ whnf pF90Func snippetFreeFuncComplex
23+ [ bench " statement (expr)" $ whnf pF90Stmt snippetFreeStmtExpr
24+ , bench " statement (assign)" $ whnf pF90Stmt snippetFreeStmtDeclAssign
25+ , bench " function" $ whnf pF90Func snippetFreeFunc
26+ ]
27+ , bgroup " Fortran 66"
28+ [ bench " statement (expr)" $ whnf pF66Stmt snippetFixedStmt
29+ , bench " function" $ whnf pF90Func snippetFixedFunc
2330 ]
2431 ]
2532 ]
2633
34+ --------------------------------------------------------------------------------
35+
2736pF90Stmt :: ByteString -> Statement A0
2837pF90Stmt = parseFree Fortran90 F90. statementParser
2938
3039pF90Func :: ByteString -> ProgramUnit A0
3140pF90Func = parseFree Fortran90 F90. functionParser
3241
42+ pF66Stmt :: ByteString -> Statement A0
43+ pF66Stmt = parseFixed Fortran66 F66. statementParser
44+
3345parseFree :: FortranVersion
3446 -> Parse LexFree. AlexInput LexFree. Token a -> ByteString -> a
3547parseFree ver parser src = evalParse parser parserState
3648 where parserState = LexFree. initParseState src ver " <unknown>"
3749
50+ parseFixed :: FortranVersion
51+ -> Parse LexFixed. AlexInput LexFixed. Token a -> ByteString -> a
52+ parseFixed ver parser src = evalParse parser parserState
53+ where parserState = LexFixed. initParseState src ver " <unknown>"
54+
3855--------------------------------------------------------------------------------
3956
40- snippetFreeStmt :: ByteString
41- snippetFreeStmt = programListing $
57+ snippetFreeStmtExpr :: ByteString
58+ snippetFreeStmtExpr = programListing $
59+ [ " x = y*2 + z - 1"
60+ ]
61+
62+ snippetFreeStmtDeclAssign :: ByteString
63+ snippetFreeStmtDeclAssign = programListing $
4264 [ " character(5) :: assign_in_decl*5 = \" test!\" "
4365 ]
4466
45- snippetFreeFuncComplex :: ByteString
46- snippetFreeFuncComplex = programListing $
67+ snippetFreeFunc :: ByteString
68+ snippetFreeFunc = programListing $
4769 [ " integer function f(x, y, z) result(i)"
4870 , " print *, i"
4971 , " i = (i - 1)"
@@ -52,6 +74,21 @@ snippetFreeFuncComplex = programListing $
5274
5375--------------------------------------------------------------------------------
5476
77+ snippetFixedStmt :: ByteString
78+ snippetFixedStmt = programListing $
79+ [ " x = y*2 + z - 1"
80+ ]
81+
82+ snippetFixedFunc :: ByteString
83+ snippetFixedFunc = programListing $
84+ [ " subroutine f(x, y, z)"
85+ , " print *, i"
86+ , " i = (i - 1)"
87+ , " end"
88+ ]
89+
90+ --------------------------------------------------------------------------------
91+
5592-- | unlines but without the trailing newline
5693programListing :: [String ] -> ByteString
5794programListing = strToByteString . intercalate " \n "
0 commit comments