Clean up the tree representation of inputs
This commit is contained in:
parent
0f5a6ae805
commit
eae0f9d1d8
28
fco/Parse.hs
28
fco/Parse.hs
|
@ -238,11 +238,14 @@ alternation
|
|||
<|> do { r <- replicator ; eol ; indent ; a <- alternative ; outdent ; return $ N.PriAltRep r a } }
|
||||
<?> "alternation"
|
||||
|
||||
-- The reason the CASE guards end up here is because they have to be handled
|
||||
-- specially: you can't tell until parsing the guts of the CASE what the processes
|
||||
-- are.
|
||||
alternative
|
||||
= guardedAlternative
|
||||
<|> alternation
|
||||
<|> try (do { b <- boolean ; sAmp ; c <- channel ; sQuest ; sCASE ; eol ; indent ; vs <- many1 variant ; outdent ; return $ N.InCaseGuard b c vs })
|
||||
<|> try (do { c <- channel ; sQuest ; sCASE ; eol ; indent ; vs <- many1 variant ; outdent ; return $ N.InCase c vs })
|
||||
<|> try (do { b <- boolean ; sAmp ; c <- channel ; sQuest ; sCASE ; eol ; indent ; vs <- many1 variant ; outdent ; return $ N.CondGuard b (N.In c (N.InCase vs)) })
|
||||
<|> try (do { c <- channel ; sQuest ; sCASE ; eol ; indent ; vs <- many1 variant ; outdent ; return $ N.In c (N.InCase vs) })
|
||||
<|> do { s <- specification ; a <- alternative ; return $ N.Decl s a }
|
||||
<?> "alternative"
|
||||
|
||||
|
@ -267,7 +270,7 @@ caseExpression
|
|||
<?> "caseExpression"
|
||||
|
||||
caseInput
|
||||
= do { c <- channel ; sQuest ; sCASE ; eol ; indent ; vs <- many1 variant ; outdent ; return $ N.InCase c vs }
|
||||
= do { c <- channel ; sQuest ; sCASE ; eol ; indent ; vs <- many1 variant ; outdent ; return $ N.In c (N.InCase vs) }
|
||||
<?> "caseInput"
|
||||
|
||||
-- This is also used for timers and ports, since the syntax is identical (and
|
||||
|
@ -444,33 +447,28 @@ functionHeader
|
|||
|
||||
guard
|
||||
= try input
|
||||
<|> try (do { b <- boolean ; sAmp ; i <- input ; return $ N.Guarded b i })
|
||||
<|> try (do { b <- boolean ; sAmp ; sSKIP ; eol ; return $ N.Guarded b N.Skip })
|
||||
<|> try (do { b <- boolean ; sAmp ; i <- input ; return $ N.CondGuard b i })
|
||||
<|> try (do { b <- boolean ; sAmp ; sSKIP ; eol ; return $ N.CondGuard b N.Skip })
|
||||
<?> "guard"
|
||||
|
||||
guardedAlternative
|
||||
= do { g <- guard ; indent ; p <- process ; outdent ; return $ N.Guarded g p }
|
||||
= do { g <- guard ; indent ; p <- process ; outdent ; return $ N.Guard g p }
|
||||
<?> "guardedAlternative"
|
||||
|
||||
guardedChoice
|
||||
= do { b <- boolean ; eol ; indent ; p <- process ; outdent ; return $ N.Guarded b p }
|
||||
= do { b <- boolean ; eol ; indent ; p <- process ; outdent ; return $ N.Choice b p }
|
||||
<?> "guardedChoice"
|
||||
|
||||
hexDigits
|
||||
= do { d <- many1 hexDigit ; return $ N.LitHex d }
|
||||
<?> "hexDigits"
|
||||
|
||||
-- XXX how does the syntax handle multiline regular CASE inputs?
|
||||
-- chan ? CASE
|
||||
-- foo
|
||||
-- ...
|
||||
|
||||
input
|
||||
= do c <- channel
|
||||
sQuest
|
||||
(do { sCASE ; tl <- taggedList ; eol ; return $ N.InTag c tl }
|
||||
<|> do { sAFTER ; e <- expression ; eol ; return $ N.InAfter c e }
|
||||
<|> do { is <- sepBy1 inputItem sSemi ; eol ; return $ N.In c is })
|
||||
(do { sCASE ; tl <- taggedList ; eol ; return $ N.In c (N.InTag tl) }
|
||||
<|> do { sAFTER ; e <- expression ; eol ; return $ N.In c (N.InAfter e) }
|
||||
<|> do { is <- sepBy1 inputItem sSemi ; eol ; return $ N.In c (N.InSimple is) })
|
||||
<?> "input"
|
||||
|
||||
inputItem
|
||||
|
|
|
@ -49,12 +49,11 @@ nodeToSExp node
|
|||
N.AltRep a b -> wrap2 "alt-rep" (top a) (top b)
|
||||
N.PriAlt a -> wrapl "pri-alt" (map top a)
|
||||
N.PriAltRep a b -> wrap2 "pri-alt-rep" (top a) (top b)
|
||||
N.In a b -> wrapl1 "?" (top a) (map top b)
|
||||
N.In a (N.InSimple b) -> wrapl1 "?" (top a) (map top b)
|
||||
N.Variant a b -> wrap2 "variant" (top a) (top b)
|
||||
N.InCase a b -> wrapl1 "?case" (top a) (map top b)
|
||||
N.InCaseGuard a b c -> wrapl2 "?case-guarded" (top a) (top b) (map top c)
|
||||
N.InTag a b -> wrap2 "?case-tag" (top a) (top b)
|
||||
N.InAfter a b -> wrap2 "?after" (top a) (top b)
|
||||
N.In a (N.InCase b) -> wrapl1 "?case" (top a) (map top b)
|
||||
N.In a (N.InTag b) -> wrap2 "?case-tag" (top a) (top b)
|
||||
N.In a (N.InAfter b) -> wrap2 "?after" (top a) (top b)
|
||||
N.Out a b -> wrapl1 "!" (top a) (map top b)
|
||||
N.OutCase a b c -> wrapl2 "!case" (top a) (top b) (map top c)
|
||||
N.ExpList a -> wrapl "exp-list" (map top a)
|
||||
|
@ -116,7 +115,9 @@ nodeToSExp node
|
|||
N.Call a b -> wrapl1 "call" (top a) (map top b)
|
||||
N.BytesIn a -> wrap "bytesin" (top a)
|
||||
N.OffsetOf a b -> wrap2 "offsetof" (top a) (top b)
|
||||
N.Guarded a b -> wrap2 "guarded" (top a) (top b)
|
||||
N.Guard a b -> wrap2 "guard" (top a) (top b)
|
||||
N.CondGuard a b -> wrap2 "cond" (top a) (top b)
|
||||
N.Choice a b -> wrap2 "choice" (top a) (top b)
|
||||
N.Val a -> wrap "val" (top a)
|
||||
N.ChanOf a -> wrap "chan" (top a)
|
||||
N.PortOf a -> wrap "port" (top a)
|
||||
|
@ -161,12 +162,11 @@ nodeToSOccam node
|
|||
N.AltRep a b -> wrap2 "alt" (top a) (top b)
|
||||
N.PriAlt a -> wrapl "pri-alt" (map top a)
|
||||
N.PriAltRep a b -> wrap2 "pri-alt" (top a) (top b)
|
||||
N.In a b -> wrapl1 "?" (top a) (map top b)
|
||||
N.Variant a b -> l2 (top a) (top b)
|
||||
N.InCase a b -> wrapl1 "?case" (top a) (map top b)
|
||||
N.InCaseGuard a b c -> wrapl2 "?case-guarded" (top a) (top b) (map top c)
|
||||
N.InTag a b -> wrap2 "?case" (top a) (top b)
|
||||
N.InAfter a b -> wrap2 "?after" (top a) (top b)
|
||||
N.In a (N.InSimple b) -> wrapl1 "?" (top a) (map top b)
|
||||
N.Variant a b -> wrap2 "variant" (top a) (top b)
|
||||
N.In a (N.InCase b) -> wrapl1 "?case" (top a) (map top b)
|
||||
N.In a (N.InTag b) -> wrap2 "?case-tag" (top a) (top b)
|
||||
N.In a (N.InAfter b) -> wrap2 "?after" (top a) (top b)
|
||||
N.Out a b -> wrapl1 "!" (top a) (map top b)
|
||||
N.OutCase a b c -> wrapl2 "!case" (top a) (top b) (map top c)
|
||||
N.ExpList a -> List (map top a)
|
||||
|
@ -228,7 +228,9 @@ nodeToSOccam node
|
|||
N.Call a b -> wrapl1 "call" (top a) (map top b)
|
||||
N.BytesIn a -> wrap "bytesin" (top a)
|
||||
N.OffsetOf a b -> wrap2 "offsetof" (top a) (top b)
|
||||
N.Guarded a b -> wrap2 "guarded" (top a) (top b)
|
||||
N.Guard a b -> List [top a, top b]
|
||||
N.CondGuard a b -> wrap2 "cond" (top a) (top b)
|
||||
N.Choice a b -> List [top a, top b]
|
||||
N.Val a -> wrap "val" (top a)
|
||||
N.ChanOf a -> wrap "chan" (top a)
|
||||
N.PortOf a -> wrap "port" (top a)
|
||||
|
|
19
fco/Tree.hs
19
fco/Tree.hs
|
@ -11,20 +11,22 @@ data Node =
|
|||
| AltRep Node Node
|
||||
| PriAlt [Node]
|
||||
| PriAltRep Node Node
|
||||
| In Node [Node]
|
||||
-- e.g. InCase (Name "c") [Variant .., Variant ..]
|
||||
|
||||
| In Node Node
|
||||
| InSimple [Node]
|
||||
-- e.g. In (Name "c") (InCase [Variant .., Variant ..])
|
||||
| Variant Node Node
|
||||
| InCase Node [Node]
|
||||
| InCaseGuard Node Node [Node]
|
||||
| InCase [Node]
|
||||
-- FIXME can turn into InCase ... (Variant .. Skip)
|
||||
| InTag Node Node
|
||||
| InTag Node
|
||||
| InAfter Node
|
||||
|
||||
| Out Node [Node]
|
||||
| OutCase Node Node [Node]
|
||||
| ExpList [Node]
|
||||
| Assign [Node] Node
|
||||
| If [Node]
|
||||
| IfRep Node Node
|
||||
| InAfter Node Node
|
||||
| While Node Node
|
||||
| Par [Node]
|
||||
| ParRep Node Node
|
||||
|
@ -116,7 +118,10 @@ data Node =
|
|||
| BytesIn Node
|
||||
| OffsetOf Node Node
|
||||
|
||||
| Guarded Node Node
|
||||
| Guard Node Node
|
||||
| CondGuard Node Node
|
||||
|
||||
| Choice Node Node
|
||||
|
||||
| Val Node
|
||||
| ChanOf Node
|
||||
|
|
Loading…
Reference in New Issue
Block a user