Rain: added support for multiple declarations on the same line
This commit is contained in:
parent
78b032ace9
commit
8ecd472a2e
|
@ -322,8 +322,11 @@ tupleDef = do {sLeftR ; tm <- sepBy tupleDefMember sComma ; sRightR ; return tm}
|
|||
tupleDefMember = do {t <- dataType ; sColon ; n <- name ; return (n,t)}
|
||||
|
||||
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) }
|
||||
declaration = try $ do {t <- dataType; sColon ; ns <- name `sepBy1` sComma ; sSemiColon ;
|
||||
return (findMeta t, \x -> foldr (foldSpec t) x ns) }
|
||||
where
|
||||
foldSpec :: A.Type -> A.Name -> (A.Structured -> A.Structured)
|
||||
foldSpec t n = A.Spec (findMeta t) $ A.Specification (findMeta t) n $ A.Declaration (findMeta t) t
|
||||
|
||||
terminator :: A.Structured
|
||||
terminator = (A.OnlyP emptyMeta $ A.Main emptyMeta)
|
||||
|
|
|
@ -443,6 +443,9 @@ testDecl =
|
|||
,passd ("uint8: x;",1,tag3 A.Specification DontCare (simpleNamePattern "x") $ tag2 A.Declaration DontCare A.Byte)
|
||||
,passd ("?bool: bc;",2,tag3 A.Specification DontCare (simpleNamePattern "bc") $ tag2 A.Declaration DontCare $ A.Chan A.DirInput nonShared A.Bool)
|
||||
,passd ("a: b;",3,tag3 A.Specification DontCare (simpleNamePattern "b") $ tag2 A.Declaration DontCare (tag1 A.UserDataType $ tag3 A.Name DontCare A.DataTypeName "a"))
|
||||
|
||||
,passd2 ("bool: b0,b1;",100,tag3 A.Specification DontCare (simpleNamePattern "b0") $ tag2 A.Declaration DontCare A.Bool,
|
||||
tag3 A.Specification DontCare (simpleNamePattern "b1") $ tag2 A.Declaration DontCare A.Bool)
|
||||
|
||||
|
||||
,fail ("bool:;",RP.declaration)
|
||||
|
@ -452,6 +455,8 @@ testDecl =
|
|||
,fail ("bool b",RP.declaration)
|
||||
,fail ("bool b;",RP.declaration)
|
||||
,fail ("bool:?b;",RP.declaration)
|
||||
,fail ("bool:b,;",RP.declaration)
|
||||
,fail ("bool: b0 b1;",RP.declaration)
|
||||
]
|
||||
where
|
||||
passd :: (String,Int,Pattern) -> ParseTest (Meta, A.Structured -> A.Structured)
|
||||
|
@ -459,6 +464,11 @@ testDecl =
|
|||
check :: String -> Pattern -> (Meta, A.Structured -> A.Structured) -> Assertion
|
||||
check msg spec (_,act) = assertPatternMatch msg (tag3 A.Spec DontCare spec $ A.Several m []) (act $ A.Several m [])
|
||||
|
||||
passd2 :: (String,Int,Pattern,Pattern) -> ParseTest (Meta, A.Structured -> A.Structured)
|
||||
passd2 (code,index,expOuter,expInner) = pass(code,RP.declaration,check2 ("testDecl " ++ (show index)) expOuter expInner)
|
||||
check2 :: String -> Pattern -> Pattern -> (Meta, A.Structured -> A.Structured) -> Assertion
|
||||
check2 msg specOuter specInner (_,act) = assertPatternMatch msg (tag3 A.Spec DontCare specOuter $ tag3 A.Spec DontCare specInner $ A.Several m []) (act $ A.Several m [])
|
||||
|
||||
testComm :: [ParseTest A.Process]
|
||||
testComm =
|
||||
[
|
||||
|
|
Loading…
Reference in New Issue
Block a user