From ab0301a342a32a7b041c6d4b1897ff7b6dde6f76 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sat, 17 May 2008 14:24:45 +0000 Subject: [PATCH] Made the Rain parser actually record an unknown (to-be-inferred) type for numeric literals --- data/CompState.hs | 13 +++++++++++-- frontends/ParseRain.hs | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/data/CompState.hs b/data/CompState.hs index 5fb2948..9a4d93c 100644 --- a/data/CompState.hs +++ b/data/CompState.hs @@ -112,7 +112,8 @@ data CompState = CompState { csAdditionalArgs :: Map String [A.Actual], csParProcs :: Set A.Name, csUnifyLookup :: Map UnifyIndex UnifyValue, - csUnifyPairs :: [(UnifyValue, UnifyValue)] + csUnifyPairs :: [(UnifyValue, UnifyValue)], + csUnifyId :: Int } deriving (Data, Typeable) @@ -144,7 +145,8 @@ emptyState = CompState { csAdditionalArgs = Map.empty, csParProcs = Set.empty, csUnifyLookup = Map.empty, - csUnifyPairs = [] + csUnifyPairs = [], + csUnifyId = 0 } -- | Class of monads which keep a CompState. @@ -368,3 +370,10 @@ ghostVarPrefix = "##" -- | A suffix put on all ghost variables, such as Rain's timers ghostVarSuffix :: String ghostVarSuffix = "_##" + +-- | A new identifer for the unify types in the tree +getUniqueIdentifer :: CSM m => m Int +getUniqueIdentifer = do st <- get + let n = csUnifyId st + put st {csUnifyId = n + 1} + return n \ No newline at end of file diff --git a/frontends/ParseRain.hs b/frontends/ParseRain.hs index 655517f..2241506 100644 --- a/frontends/ParseRain.hs +++ b/frontends/ParseRain.hs @@ -40,6 +40,15 @@ import Utils type RainState = CompState type RainParser = GenParser L.Token RainState +instance CSMR (GenParser tok CompState) where + getCompState = getState + +-- We can expose only part of the state to make it look like we are only using +-- CompState: +instance MonadState CompState (GenParser tok CompState) where + get = getState + put = setState + instance Die (GenParser tok st) where dieReport (Just m, err) = fail $ packMeta m err dieReport (Nothing, err) = fail err @@ -195,16 +204,19 @@ literalCharacter testToken (L.TokCharLiteral c) = Just c testToken _ = Nothing -integer :: RainParser A.LiteralRepr +integer :: RainParser (Integer, A.LiteralRepr) integer = do (m,d) <- getToken testToken - return $ A.IntLiteral m d + return $ (read d, A.IntLiteral m d) where testToken (L.TokDecimalLiteral d) = Just d testToken _ = Nothing integerLiteral :: RainParser A.Expression -integerLiteral = do {i <- integer ; return $ A.Literal (findMeta i) A.Int i} +integerLiteral = do (val, i) <- integer + u <- getUniqueIdentifer + let m = findMeta i + return $ A.Literal m (A.UnknownNumLitType m u val) i listLiteral :: RainParser A.Expression listLiteral