diff --git a/LexRain.x b/LexRain.x index 5d47f8d..ef0389a 100644 --- a/LexRain.x +++ b/LexRain.x @@ -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" diff --git a/RainParse.hs b/RainParse.hs index bed1c88..6398b5d 100644 --- a/RainParse.hs +++ b/RainParse.hs @@ -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" diff --git a/RainParseTest.hs b/RainParseTest.hs index ba8360e..9dfd485 100644 --- a/RainParseTest.hs +++ b/RainParseTest.hs @@ -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