Made the Rain parser actually record an unknown (to-be-inferred) type for numeric literals

This commit is contained in:
Neil Brown 2008-05-17 14:24:45 +00:00
parent cd0c8d2901
commit ab0301a342
2 changed files with 26 additions and 5 deletions

View File

@ -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

View File

@ -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