@@ -1,4 +1,4 @@
1−{-# LANGUAGE PatternGuards #-}
1+{-# LANGUAGE PatternGuards, ScopedTypeVariables #-}
2-- | Parse the full Idris language.
2-- | Parse the full Idris language.
3module Idris.Parser where
3module Idris.Parser where
@@ -800,8 +800,17 @@ pCaseOpt syn = do lhs <- pExpr (syn { inPattern = True })
800 symbol "=>"; rhs <- pExpr syn
800 symbol "=>"; rhs <- pExpr syn
801 return (lhs, rhs)
801 return (lhs, rhs)
803+-- bit of a hack here. If the integer doesn't fit in an Int, treat it as a
804+-- big integer, otherwise try fromInteger and the constants as alternatives.
805+-- a better solution would be to fix fromInteger to work with Integer, as the
806+-- name suggests, rather than Int
803modifyConst :: SyntaxInfo -> FC -> PTerm -> PTerm
808modifyConst :: SyntaxInfo -> FC -> PTerm -> PTerm
804modifyConst syn fc (PConstant (BI x))
809modifyConst syn fc (PConstant (BI x))
810+ | not (fitsInt x) = PAlternative False
812+ PApp fc (PRef fc (UN "fromInteger"))
813+ [pexp (PConstant (I (fromInteger x)))]]
805 | not (inPattern syn)
814 | not (inPattern syn)
806 = PAlternative False
815 = PAlternative False
807 [PApp fc (PRef fc (UN "fromInteger")) [pexp (PConstant (I (fromInteger x)))],
816 [PApp fc (PRef fc (UN "fromInteger")) [pexp (PConstant (I (fromInteger x)))],
@@ -810,6 +819,11 @@ modifyConst syn fc (PConstant (BI x))
810 [PConstant (I (fromInteger x)), PConstant (BI x)]
819 [PConstant (I (fromInteger x)), PConstant (BI x)]
811modifyConst syn fc x = x
820modifyConst syn fc x = x
822+fitsInt :: Integer -> Bool
823+fitsInt x = let xInt :: Int = fromInteger x
824+ xInteger :: Integer = toInteger xInt in
813pList syn = do lchar '['; fc <- pfc; xs <- sepBy (pExpr syn) (lchar ','); lchar ']'
827pList syn = do lchar '['; fc <- pfc; xs <- sepBy (pExpr syn) (lchar ','); lchar ']'
814 return (mkList fc xs)
828 return (mkList fc xs)