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 ;
|
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) }
|
return (findMeta t, A.Spec (findMeta t) $ A.Specification (findMeta t) n $ A.Declaration (findMeta t) t) }
|
||||||
|
|
||||||
topLevelDecl :: RainParser A.Structured
|
terminator :: A.Structured
|
||||||
topLevelDecl = do {m <- sProcess ; procName <- name ; params <- tupleDef ; body <- block ;
|
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
|
return $ A.Spec m
|
||||||
(A.Specification m procName (A.Proc m A.PlainSpec (formaliseTuple params) body))
|
(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 :: RainParser (A.Process, CompState)
|
||||||
rainSourceFile
|
rainSourceFile
|
||||||
|
|
|
@ -342,17 +342,29 @@ testTopLevelDecl :: [ParseTest A.Structured]
|
||||||
testTopLevelDecl =
|
testTopLevelDecl =
|
||||||
[
|
[
|
||||||
pass ("process noargs() {}", RP.topLevelDecl,
|
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])
|
(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.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,
|
, 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")]
|
(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.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 () {}", RP.topLevelDecl)
|
, fail ("process () {}", RP.topLevelDecl)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user