Rain: added parsing support for return statements
This commit is contained in:
parent
989bb1c757
commit
909fe0ea6b
|
@ -40,7 +40,7 @@ $hexDigit = [0-9 a-f A-F]
|
|||
| ".."
|
||||
| "process" | "function"
|
||||
| "pareach" | "seqeach" | "par" | "seq"
|
||||
| "run"
|
||||
| "run" | "return"
|
||||
| "if" | "while" | "else"
|
||||
| "sint8" | "sint16" | "sint32" | "sint64"
|
||||
| "uint8" | "uint16" | "uint32" | "uint64"
|
||||
|
|
|
@ -84,6 +84,7 @@ sWhile = reserved "while"
|
|||
sProcess = reserved "process"
|
||||
sFunction = reserved "function"
|
||||
sRun = reserved "run"
|
||||
sReturn = reserved "return"
|
||||
--}}}
|
||||
|
||||
--{{{Operators
|
||||
|
@ -251,6 +252,10 @@ innerBlock = do {m <- sLeftC ; lines <- linesToEnd ; return $ A.Several m lines}
|
|||
linesToEnd :: RainParser [A.Structured]
|
||||
linesToEnd = do {(m,decl) <- declaration ; rest <- linesToEnd ; return [decl $ A.Several m rest]}
|
||||
<|> do {st <- statement ; rest <- linesToEnd ; return $ (wrapProc st) : rest}
|
||||
--Although return is technically a statement, we parse it here because it can only occur inside a block,
|
||||
--and we don't want to wrap it in an A.OnlyP:
|
||||
<|> do {m <- sReturn ; exp <- expression ; sSemiColon ; rest <- linesToEnd ;
|
||||
return $ (A.OnlyEL m $ A.ExpressionList (findMeta exp) [exp]) : rest}
|
||||
<|> do {sRightC ; return []}
|
||||
<?> "statement, declaration, or end of block"
|
||||
|
||||
|
|
|
@ -432,6 +432,14 @@ testTopLevelDecl =
|
|||
]
|
||||
)
|
||||
|
||||
,pass ("function uint8: id(uint8: x) {return x;}", RP.topLevelDecl,
|
||||
assertPatternMatch "testTopLevelDecl 101" $ tag2 A.Several DontCare [tag3 A.Spec DontCare
|
||||
(tag3 A.Specification DontCare (simpleNamePattern "id") $
|
||||
tag5 A.Function DontCare A.PlainSpec [A.Byte] [tag3 A.Formal A.ValAbbrev A.Byte (simpleNamePattern "x")] $
|
||||
(tag2 A.OnlyP DontCare $ tag2 A.Seq DontCare $ tag2 A.Several DontCare [tag2 A.OnlyEL DontCare $ tag2 A.ExpressionList DontCare [exprVariablePattern "x"]])
|
||||
) (tag2 A.OnlyP DontCare $ tag1 A.Main DontCare)
|
||||
]
|
||||
)
|
||||
]
|
||||
|
||||
nonShared :: A.ChanAttributes
|
||||
|
|
Loading…
Reference in New Issue
Block a user