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" | "return" | "now"
| "wait" | "for" | "until" | "wait" | "for" | "until"
| "if" | "while" | "else" | "if" | "while" | "else"
| "pri" | "alt" | "pri" | "alt" | "poison"
| "sint8" | "sint16" | "sint32" | "sint64" | "sint8" | "sint16" | "sint32" | "sint64"
| "uint8" | "uint16" | "uint32" | "uint64" | "uint8" | "uint16" | "uint32" | "uint64"
| "int" | "bool" | "time" | "channel" | "int" | "bool" | "time" | "channel"

View File

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