From 4a36d578c0a793bc9cb2882f52196a4066c004bb Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 3 Apr 2009 21:03:19 +0000 Subject: [PATCH] Added a check that the names being scoped out match the names that were scoped in, which helps find bugs in the parser --- frontends/ParseOccam.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontends/ParseOccam.hs b/frontends/ParseOccam.hs index 48a6880..ac437da 100644 --- a/frontends/ParseOccam.hs +++ b/frontends/ParseOccam.hs @@ -370,7 +370,7 @@ handleSpecs specs inner specMarker (ss, after) <- specs ss' <- mapM scopeInSpec ss v <- inner - mapM scopeOutSpec ss' + mapM scopeOutSpec (reverse ss') after return $ foldl (\e s -> specMarker m s e) v ss' @@ -425,7 +425,10 @@ scopeOut :: A.Name -> OccParser () scopeOut n@(A.Name m _) = do st <- get case csLocalNames st of - (_:rest) -> put $ st { csLocalNames = rest } + ((_, (old, _)):rest) + | old == n -> put $ st { csLocalNames = rest } + | otherwise -> dieInternal (Just m, "scoping out not in order; " + ++ " tried to scope out: " ++ A.nameName n ++ " but found: " ++ A.nameName old) _ -> dieInternal (Just m, "scoping out name when stack is empty") scopeInRep :: A.Name -> OccParser A.Name @@ -468,7 +471,7 @@ scopeInFormals :: [NameFormal] -> OccParser [A.Formal] scopeInFormals fs = mapM scopeInFormal fs scopeOutFormals :: [A.Formal] -> OccParser () -scopeOutFormals fs = sequence_ [scopeOut n | (A.Formal am t n) <- fs] +scopeOutFormals fs = sequence_ [scopeOut n | (A.Formal am t n) <- reverse fs] --}}}