Represent formals with a list of names declared in Tree
This commit is contained in:
parent
51c1144ca7
commit
0f5a6ae805
14
fco/Parse.hs
14
fco/Parse.hs
|
@ -417,8 +417,8 @@ fieldName
|
|||
= name
|
||||
<?> "fieldName"
|
||||
|
||||
-- This is rather different from the grammar.
|
||||
-- FIXME should this lot actually be done in a pass? probably...
|
||||
-- This is rather different from the grammar, since I had some difficulty
|
||||
-- getting Parsec to parse it as a list of lists of arguments.
|
||||
formalList
|
||||
= do { sLeftR ; fs <- sepBy formalArg sComma ; sRightR ; return $ markTypes fs }
|
||||
<?> "formalList"
|
||||
|
@ -431,12 +431,12 @@ formalList
|
|||
markTypes :: [(Maybe N.Node, N.Node)] -> [N.Node]
|
||||
markTypes [] = []
|
||||
markTypes ((Nothing, _):_) = error "Formal list must start with a type"
|
||||
markTypes ((Just ft,fn):is) = (N.Formal ft fn) : markRest ft is
|
||||
markTypes ((Just ft, fn):is) = markRest ft [fn] is
|
||||
|
||||
markRest :: N.Node -> [(Maybe N.Node, N.Node)] -> [N.Node]
|
||||
markRest _ [] = []
|
||||
markRest t ((Nothing, n):is) = (N.Formal t n) : markRest t is
|
||||
markRest _ ((Just t, n):is) = (N.Formal t n) : markRest t is
|
||||
markRest :: N.Node -> [N.Node] -> [(Maybe N.Node, N.Node)] -> [N.Node]
|
||||
markRest lt ns [] = [N.Formals lt ns]
|
||||
markRest lt ns ((Nothing, n):is) = markRest lt (ns ++ [n]) is
|
||||
markRest lt ns ((Just t, n):is) = (markRest lt ns []) ++ (markRest t [n] is)
|
||||
|
||||
functionHeader
|
||||
= do { sFUNCTION ; n <- name ; fs <- formalList ; return $ (n, fs) }
|
||||
|
|
|
@ -23,17 +23,6 @@ nestDecls l n = foldl (\a b -> b a) n [N.IntDecl n d | (N.Name n, d) <- l]
|
|||
markDecls :: Transform ()
|
||||
markDecls next top node
|
||||
= case node of
|
||||
N.Decl (N.Proc nn@(N.Name n) args code) body -> do
|
||||
body' <- top body
|
||||
code' <- top code
|
||||
let pdecl = nestDecls [(n, d) | d@(N.Formal _ n) <- args] (N.Proc nn args code')
|
||||
return $ N.IntDecl n pdecl body'
|
||||
N.Decl (N.Func nn@(N.Name n) args rets code) body -> do
|
||||
error "blah"
|
||||
body' <- top body
|
||||
code' <- top code
|
||||
let pdecl = nestDecls [(n, d) | d@(N.Formal _ n) <- args] (N.Func nn args rets code')
|
||||
return $ N.IntDecl n pdecl body'
|
||||
-- FIXME same for functions
|
||||
N.Decl d body -> do
|
||||
body' <- top body
|
||||
|
|
|
@ -89,7 +89,7 @@ nodeToSExp node
|
|||
N.Protocol a b -> wrapl1 "protocol" (top a) (map top b)
|
||||
N.TaggedProtocol a b -> wrapl1 "protocol-tagged" (top a) (map top b)
|
||||
N.Tag a b -> wrapl1 "tag" (top a) (map top b)
|
||||
N.Formal a b -> wrap2 "formal" (top a) (top b)
|
||||
N.Formals a b -> wrapl1 "formal" (top a) (map top b)
|
||||
N.Proc a b c -> wrap3 "proc" (top a) (List $ map top b) (top c)
|
||||
N.Func a b c d -> wrap4 "function" (top a) (List $ map top b) (List $ map top c) (top d)
|
||||
N.FuncIs a b c d -> wrap4 "function-is" (top a) (List $ map top b) (List $ map top c) (top d)
|
||||
|
@ -201,7 +201,7 @@ nodeToSOccam node
|
|||
N.Protocol a b -> wrapl1 "protocol" (top a) (map top b)
|
||||
N.TaggedProtocol a b -> wrapl1 "protocol" (top a) (map top b)
|
||||
N.Tag a b -> List ((top a) : (map top b))
|
||||
N.Formal a b -> l2 (top a) (top b)
|
||||
N.Formals a b -> List ((top a) : (map top b))
|
||||
N.Proc a b c -> wrap3 "proc" (top a) (List $ map top b) (top c)
|
||||
N.Func a b c d -> wrap4 "function" (top a) (List $ map top b) (List $ map top c) (top d)
|
||||
N.FuncIs a b c d -> wrap4 "function-is" (top a) (List $ map top b) (List $ map top c) (top d)
|
||||
|
|
|
@ -55,8 +55,8 @@ data Node =
|
|||
| Protocol Node [Node]
|
||||
| TaggedProtocol Node [Node]
|
||||
| Tag Node [Node]
|
||||
-- e.g. Proc (Name "out.string") [Formal Int (Name "x"), Formal Bool (Name "y")]
|
||||
| Formal Node Node
|
||||
-- e.g. Proc (Name "out.string") [Formals Int [Name "x", Name "y"], Formal Bool [Name "z"]]
|
||||
| Formals Node [Node]
|
||||
| Proc Node [Node] Node
|
||||
| Func Node [Node] [Node] Node
|
||||
| FuncIs Node [Node] [Node] Node
|
||||
|
|
Loading…
Reference in New Issue
Block a user