@@ -21,13 +21,18 @@ eParser sourceCode =
2121 paddedSourceCode = B. pack $ " a = " ++ sourceCode
2222 parseState = initParseState paddedSourceCode Fortran2003 " <unknown>"
2323
24+ simpleParser :: Parse AlexInput Token a -> String -> a
25+ simpleParser p sourceCode =
26+ evalParse p $ initParseState (B. pack sourceCode) Fortran2003 " <unknown>"
27+
2428sParser :: String -> Statement ()
25- sParser sourceCode =
26- evalParse statementParser $ initParseState (B. pack sourceCode) Fortran2003 " <unknown>"
29+ sParser = simpleParser statementParser
2730
2831fParser :: String -> ProgramUnit ()
29- fParser sourceCode =
30- evalParse functionParser $ initParseState (B. pack sourceCode) Fortran2003 " <unknown>"
32+ fParser = simpleParser functionParser
33+
34+ bParser :: String -> Block ()
35+ bParser = simpleParser blockParser
3136
3237spec :: Spec
3338spec =
@@ -141,16 +146,32 @@ spec =
141146 sParser " real, protected, public :: x" `shouldBe'` st1
142147 sParser " protected x" `shouldBe'` st2
143148
144- describe " labelled where" $ do
145- it " parses where construct statement" $
146- sParser " foo: where (.true.)" `shouldBe'` StWhereConstruct () u (Just " foo" ) valTrue
147-
148- it " parses elsewhere statement" $
149- sParser " elsewhere ab101" `shouldBe'` StElsewhere () u (Just " ab101" ) Nothing
150-
151- it " parses elsewhere statement" $ do
152- let exp = ExpBinary () u GT (varGen " a" ) (varGen " b" )
153- sParser " elsewhere (a > b) A123" `shouldBe'` StElsewhere () u (Just " a123" ) (Just exp )
154-
155- it " parses endwhere statement" $
156- sParser " endwhere foo1" `shouldBe'` StEndWhere () u (Just " foo1" )
149+ describe " labelled where" $ do
150+ it " parses where construct statement" $
151+ sParser " foo: where (.true.)" `shouldBe'` StWhereConstruct () u (Just " foo" ) valTrue
152+
153+ it " parses elsewhere statement" $
154+ sParser " elsewhere ab101" `shouldBe'` StElsewhere () u (Just " ab101" ) Nothing
155+
156+ it " parses elsewhere statement" $ do
157+ let exp = ExpBinary () u GT (varGen " a" ) (varGen " b" )
158+ sParser " elsewhere (a > b) A123" `shouldBe'` StElsewhere () u (Just " a123" ) (Just exp )
159+
160+ it " parses endwhere statement" $
161+ sParser " endwhere foo1" `shouldBe'` StEndWhere () u (Just " foo1" )
162+
163+ describe " associate block" $ do
164+ it " parses multiple assignment associate block" $ do
165+ let text = unlines [ " associate (x => a, y => (a * b))"
166+ , " print *, x"
167+ , " print *, y"
168+ , " end associate" ]
169+ expected = BlAssociate () u Nothing Nothing abbrevs body' Nothing
170+ body' = [blStmtPrint " x" , blStmtPrint " y" ]
171+ blStmtPrint x = BlStatement () u Nothing (stmtPrint x)
172+ stmtPrint x = StPrint () u starVal (Just $ AList () u [ varGen x ])
173+ abbrevs = AList () u [abbrev " x" (expValVar " a" ), abbrev " y" (expBinVars Multiplication " a" " b" )]
174+ abbrev var expr = ATuple () u (expValVar var) expr
175+ expValVar x = ExpValue () u (ValVariable x)
176+ expBinVars op x1 x2 = ExpBinary () u op (expValVar x1) (expValVar x2)
177+ bParser text `shouldBe'` expected
0 commit comments