@@ -1,4 +1,4 @@
1−{-# LANGUAGE PatternGuards #-}
1+{-# LANGUAGE PatternGuards, ScopedTypeVariables #-}
22-- | Parse the full Idris language.
33module Idris.Parser where
44
@@ -800,8 +800,17 @@ pCaseOpt syn = do lhs <- pExpr (syn { inPattern = True })
800800 symbol "=>"; rhs <- pExpr syn
801801 return (lhs, rhs)
802802
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
807+
803808modifyConst :: SyntaxInfo -> FC -> PTerm -> PTerm
804809modifyConst syn fc (PConstant (BI x))
810+ | not (fitsInt x) = PAlternative False
811+ [PConstant (BI x),
812+ PApp fc (PRef fc (UN "fromInteger"))
813+ [pexp (PConstant (I (fromInteger x)))]]
805814 | not (inPattern syn)
806815 = PAlternative False
807816 [PApp fc (PRef fc (UN "fromInteger")) [pexp (PConstant (I (fromInteger x)))],
@@ -810,6 +819,11 @@ modifyConst syn fc (PConstant (BI x))
810819 [PConstant (I (fromInteger x)), PConstant (BI x)]
811820modifyConst syn fc x = x
812821
822+fitsInt :: Integer -> Bool
823+fitsInt x = let xInt :: Int = fromInteger x
824+ xInteger :: Integer = toInteger xInt in
825+ x == xInteger
826+
813827pList syn = do lchar '['; fc <- pfc; xs <- sepBy (pExpr syn) (lchar ','); lchar ']'
814828 return (mkList fc xs)
815829 where