Added support for poison to the lexer and parser (and associated tests)

This commit is contained in:
Neil Brown 2008-09-12 14:39:57 +00:00
parent ec25ff9901
commit 4c263dba7e
3 changed files with 17 additions and 3 deletions

View File

@ -42,7 +42,7 @@ $hexDigit = [0-9 a-f A-F]
| "return" | "now"
| "wait" | "for" | "until"
| "if" | "while" | "else"
| "pri" | "alt"
| "pri" | "alt" | "poison"
| "sint8" | "sint16" | "sint32" | "sint64"
| "uint8" | "uint16" | "uint32" | "uint64"
| "int" | "bool" | "time" | "channel"

View File

@ -56,7 +56,7 @@ instance Die (GenParser tok st) where
sLeftQ, sRightQ, sLeftR, sRightR, sLeftC, sRightC, sSemiColon, sColon,
sComma, sIn, sOut, sDots, sPar, sSeq, sAlt, sPri, sSeqeach, sPareach,
sChannel, sOne2One, sIf, sElse, sWhile, sProcess, sFunction, sReturn,
sWait, sFor, sUntil :: RainParser Meta
sWait, sFor, sUntil, sPoison :: RainParser Meta
--{{{ Symbols
sLeftQ = reserved "["
@ -92,6 +92,7 @@ sReturn = reserved "return"
sWait = reserved "wait"
sFor = reserved "for"
sUntil = reserved "until"
sPoison = reserved "poison"
--}}}
--{{{Operators
@ -462,6 +463,7 @@ statement
rainTimerName) wm}
<|> try (comm False)
<|> alt
<|> do {m <- sPoison ; ch <- lvalue; sSemiColon ; return $ A.InjectPoison m ch}
<|> try (do { lv <- lvalue ; op <- assignOp ; exp <- expression ; sSemiColon ;
case op of
(m', Just dyOp) -> return (A.Assign m' [lv] (A.ExpressionList m' [(A.Dyadic m' dyOp (A.ExprVariable (findMeta lv) lv) exp)]))

View File

@ -731,7 +731,18 @@ testTime =
]
where
timer = mVariable RP.rainTimerName
testPoison :: [ParseTest A.Process]
testPoison =
[
pass ("poison x;", RP.statement, assertPatternMatch "testPoison 0" $
mInjectPoison $ variablePattern "x")
,fail ("poison 0;", RP.statement)
,fail ("poison 0", RP.statement)
,fail ("poison;", RP.statement)
,fail ("poison", RP.statement)
]
--Returns the list of tests:
tests :: Test
tests = TestLabel "ParseRainTest" $ TestList
@ -752,6 +763,7 @@ tests = TestLabel "ParseRainTest" $ TestList
parseTests testTime,
parseTests testRun,
parseTests testDecl,
parseTests testPoison,
parseTests testTopLevelDecl
]
--TODO test: