Rain: changed the top-level parser to be able to parse multiple processes in a file
This commit is contained in:
parent
0520f3aaa0
commit
ab918eb9ab
14
RainParse.hs
14
RainParse.hs
|
@ -303,11 +303,19 @@ declaration :: RainParser (Meta,A.Structured -> A.Structured)
|
|||
declaration = try $ do {t <- dataType; sColon ; n <- name ; sSemiColon ;
|
||||
return (findMeta t, A.Spec (findMeta t) $ A.Specification (findMeta t) n $ A.Declaration (findMeta t) t) }
|
||||
|
||||
topLevelDecl :: RainParser A.Structured
|
||||
topLevelDecl = do {m <- sProcess ; procName <- name ; params <- tupleDef ; body <- block ;
|
||||
terminator :: A.Structured
|
||||
terminator = (A.OnlyP emptyMeta $ A.Main emptyMeta)
|
||||
|
||||
processDecl :: RainParser A.Structured
|
||||
processDecl = do {m <- sProcess ; procName <- name ; params <- tupleDef ; body <- block ;
|
||||
return $ A.Spec m
|
||||
(A.Specification m procName (A.Proc m A.PlainSpec (formaliseTuple params) body))
|
||||
(A.OnlyP m $ A.Main m)}
|
||||
terminator}
|
||||
|
||||
topLevelDecl :: RainParser A.Structured
|
||||
topLevelDecl = do decls <- many processDecl
|
||||
eof
|
||||
return $ A.Several emptyMeta decls
|
||||
|
||||
rainSourceFile :: RainParser (A.Process, CompState)
|
||||
rainSourceFile
|
||||
|
|
|
@ -342,18 +342,30 @@ testTopLevelDecl :: [ParseTest A.Structured]
|
|||
testTopLevelDecl =
|
||||
[
|
||||
pass ("process noargs() {}", RP.topLevelDecl,
|
||||
assertPatternMatch "testTopLevelDecl 0" $ tag3 A.Spec DontCare
|
||||
assertPatternMatch "testTopLevelDecl 0" $ tag2 A.Several DontCare [tag3 A.Spec DontCare
|
||||
(tag3 A.Specification DontCare (simpleNamePattern "noargs") $ tag4 A.Proc DontCare A.PlainSpec ([] :: [A.Formal])
|
||||
(tag2 A.Seq DontCare $ tag2 A.Several DontCare ([] :: [A.Structured]))
|
||||
)
|
||||
(tag2 A.OnlyP DontCare $ tag1 A.Main DontCare)
|
||||
(tag2 A.OnlyP DontCare $ tag1 A.Main DontCare)]
|
||||
)
|
||||
, pass ("process onearg(int: x) {x = 0;}", RP.topLevelDecl,
|
||||
assertPatternMatch "testTopLevelDecl 1" $ tag3 A.Spec DontCare
|
||||
assertPatternMatch "testTopLevelDecl 1" $ tag2 A.Several DontCare [tag3 A.Spec DontCare
|
||||
(tag3 A.Specification DontCare (simpleNamePattern "onearg") $ tag4 A.Proc DontCare A.PlainSpec [tag3 A.Formal A.ValAbbrev A.Int (simpleNamePattern "x")]
|
||||
(tag2 A.Seq DontCare $ tag2 A.Several DontCare [tag2 A.OnlyP DontCare $ makeAssignPattern (variablePattern "x") (intLiteralPattern 0)]) )
|
||||
(tag2 A.OnlyP DontCare $ tag1 A.Main DontCare)
|
||||
(tag2 A.OnlyP DontCare $ tag1 A.Main DontCare)]
|
||||
)
|
||||
,pass ("process noargs0() {} process noargs1 () {}", RP.topLevelDecl,
|
||||
assertPatternMatch "testTopLevelDecl 2" $ tag2 A.Several DontCare [
|
||||
tag3 A.Spec DontCare
|
||||
(tag3 A.Specification DontCare (simpleNamePattern "noargs0") $ tag4 A.Proc DontCare A.PlainSpec ([] :: [A.Formal])
|
||||
(tag2 A.Seq DontCare $ tag2 A.Several DontCare ([] :: [A.Structured]))
|
||||
) (tag2 A.OnlyP DontCare $ tag1 A.Main DontCare)
|
||||
,tag3 A.Spec DontCare
|
||||
(tag3 A.Specification DontCare (simpleNamePattern "noargs1") $ tag4 A.Proc DontCare A.PlainSpec ([] :: [A.Formal])
|
||||
(tag2 A.Seq DontCare $ tag2 A.Several DontCare ([] :: [A.Structured]))
|
||||
) (tag2 A.OnlyP DontCare $ tag1 A.Main DontCare)
|
||||
]
|
||||
)
|
||||
, fail ("process", RP.topLevelDecl)
|
||||
, fail ("process () {}", RP.topLevelDecl)
|
||||
, fail ("process foo", RP.topLevelDecl)
|
||||
|
|
Loading…
Reference in New Issue
Block a user