@@ -70,13 +70,19 @@ record syn = do (doc, acc) <- try (do
70{- | Parses data declaration type (normal or codata)
70{- | Parses data declaration type (normal or codata)
71DataI ::= 'data' | 'codata';
71DataI ::= 'data' | 'codata';
73−dataI :: IdrisParser Bool
73+dataI :: IdrisParser DataOpts
74−dataI = do reserved "data"; return False
74+dataI = do reserved "data"; return []
75− <|> do reserved "codata"; return True
75+ <|> do reserved "codata"; return [Codata]
77+{- | Parses if a data should not have a default eliminator
78+DefaultEliminator ::= 'noelim'?
80+defaultEliminator :: IdrisParser DataOpts
81+defaultEliminator = do option [DefaultEliminator] (do reserved "%noelim"; return [])
77{- | Parses a data type declaration
83{- | Parses a data type declaration
78−Data ::= DocComment? Accessibility? DataI FnName TypeSig ExplicitTypeDataRest?
84+Data ::= DocComment? Accessibility? DataI DefaultEliminator FnName TypeSig ExplicitTypeDataRest?
79− | DocComment? Accessibility? DataI FnName Name* DataRest?
85+ | DocComment? Accessibility? DataI DefaultEliminator FnName Name* DataRest?
81Constructor' ::= Constructor KeepTerminator;
87Constructor' ::= Constructor KeepTerminator;
82ExplicitTypeDataRest ::= 'where' OpenBlock Constructor'* CloseBlock;
88ExplicitTypeDataRest ::= 'where' OpenBlock Constructor'* CloseBlock;
@@ -90,29 +96,31 @@ SimpleConstructorList ::=
92data_ :: SyntaxInfo -> IdrisParser PDecl
98data_ :: SyntaxInfo -> IdrisParser PDecl
93−data_ syn = do (doc, acc, co) <- try (do
99+data_ syn = do (doc, acc, dataOpts) <- try (do
94 doc <- option "" (docComment '|')
100 doc <- option "" (docComment '|')
95 pushIndent
101 pushIndent
96 acc <- optional accessibility
102 acc <- optional accessibility
103+ elim <- defaultEliminator
97 co <- dataI
104 co <- dataI
105+ let dataOpts = combineDataOpts(elim ++ co)
98− return (doc, acc, co))
106+ return (doc, acc, dataOpts))
99 fc <- getFC
107 fc <- getFC
100 tyn_in <- fnName
108 tyn_in <- fnName
101 (do try (lchar ':')
109 (do try (lchar ':')
102 popIndent
110 popIndent
103 ty <- typeExpr (allowImp syn)
111 ty <- typeExpr (allowImp syn)
104 let tyn = expandNS syn tyn_in
112 let tyn = expandNS syn tyn_in
105− option (PData doc syn fc co (PLaterdecl tyn ty)) (do
113+ option (PData doc syn fc dataOpts (PLaterdecl tyn ty)) (do
106 reserved "where"
114 reserved "where"
107 cons <- indentedBlock (constructor syn)
115 cons <- indentedBlock (constructor syn)
108 accData acc tyn (map (\ (_, n, _, _) -> n) cons)
116 accData acc tyn (map (\ (_, n, _, _) -> n) cons)
109− return $ PData doc syn fc co (PDatadecl tyn ty cons))) <|> (do
117+ return $ PData doc syn fc dataOpts (PDatadecl tyn ty cons))) <|> (do
110 args <- many name
118 args <- many name
111 let ty = bindArgs (map (const PType) args) PType
119 let ty = bindArgs (map (const PType) args) PType
112 let tyn = expandNS syn tyn_in
120 let tyn = expandNS syn tyn_in
113− option (PData doc syn fc co (PLaterdecl tyn ty)) (do
121+ option (PData doc syn fc dataOpts (PLaterdecl tyn ty)) (do
114 try (lchar '=') <|> do reserved "where"
122 try (lchar '=') <|> do reserved "where"
115− let kw = (if co then "co" else "") ++ "data "
123+ let kw = (if DefaultEliminator `elem` dataOpts then "" else "%noelim ") ++ (if Codata `elem` dataOpts then "co" else "") ++ "data "
116 let n = show tyn_in ++ " "
124 let n = show tyn_in ++ " "
117 let s = kw ++ n
125 let s = kw ++ n
118 let as = concat (intersperse " " $ map show args) ++ " "
126 let as = concat (intersperse " " $ map show args) ++ " "
@@ -129,7 +137,7 @@ data_ syn = do (doc, acc, co) <- try (do
129 do let cty = bindArgs cargs conty
137 do let cty = bindArgs cargs conty
130 return (doc, x, cty, cfc)) cons
138 return (doc, x, cty, cfc)) cons
131 accData acc tyn (map (\ (_, n, _, _) -> n) cons')
139 accData acc tyn (map (\ (_, n, _, _) -> n) cons')
132− return $ PData doc syn fc co (PDatadecl tyn ty cons')))
140+ return $ PData doc syn fc dataOpts (PDatadecl tyn ty cons')))
133 <?> "data type declaration"
141 <?> "data type declaration"
135 mkPApp :: FC -> PTerm -> [PTerm] -> PTerm
143 mkPApp :: FC -> PTerm -> [PTerm] -> PTerm
@@ -137,6 +145,8 @@ data_ syn = do (doc, acc, co) <- try (do
137 mkPApp fc t xs = PApp fc t (map pexp xs)
145 mkPApp fc t xs = PApp fc t (map pexp xs)
138 bindArgs :: [PTerm] -> PTerm -> PTerm
146 bindArgs :: [PTerm] -> PTerm -> PTerm
139 bindArgs xs t = foldr (PPi expl (MN 0 "t")) t xs
147 bindArgs xs t = foldr (PPi expl (MN 0 "t")) t xs
148+ combineDataOpts :: DataOpts -> DataOpts
149+ combineDataOpts opts = if Codata `elem` opts then delete DefaultEliminator opts else opts
142{- | Parses a type constructor declaration
152{- | Parses a type constructor declaration