on master help sign in
More record stuff.
commit0269d05baea5706fb8f2e6b451e8130bfae6d2a1 authorSune Alkaersig <sune@Sunes-MacBook-Pro.local> dateTue 31 Mar 2015, 20:55 (12 years ago) parent86bcbbc
7 files changed+137−80
src/Idris/AbsSyntax.hs+2−5 src/Idris/AbsSyntaxTree.hs+5−9 src/Idris/DeepSeq.hs+2−2 src/Idris/Elab/Record.hs+109−45 src/Idris/ElabDecls.hs+2−2 src/Idris/IBC.hs+2−4 src/Idris/ParseData.hs+15−13
src/Idris/AbsSyntax.hs+2−5
@@ -1075,11 +1075,8 @@ expandParamsD rhs ist dec ps ns (PData doc argDocs syn fc co pd)
10751075 else PDatadecl n (expandParams dec ps ns [] ty) (map econ cons)
10761076 econ (doc, argDocs, n, t, fc, fs)
10771077 = (doc, argDocs, dec n, piBindp expl ps (expandParams dec ps ns [] t), fc, fs)
1078−expandParamsD rhs ist dec ps ns (PRecord doc syn fc opts n prs pdocs fls fdocs cn cdoc csyn)
1079− = PRecord doc syn fc opts n prs pdocs
1080− fls fdocs
1081− cn cdoc csyn
1082−
1078+expandParamsD rhs ist dec ps ns d@(PRecord doc rsyn fc opts name prs pdocs fls cn cdoc csyn)
1079+ = d
10831080expandParamsD rhs ist dec ps ns (PParams f params pds)
10841081 = PParams f (ps ++ map (mapsnd (expandParams dec ps ns [])) params)
10851082 (map (expandParamsD True ist dec ps ns) pds)
src/Idris/AbsSyntaxTree.hs+5−9
@@ -599,9 +599,8 @@ data PDecl' t
599599 | PRecord (Docstring (Either Err PTerm)) SyntaxInfo FC DataOpts
600600 Name -- Record name
601601 [(Name, Plicity, t)] -- Parameters
602− [(Name, Docstring (Either Err PTerm))] -- Parameter docs
603− [(Name, Plicity, t)] -- Fields
604− [(Name, Docstring (Either Err PTerm))] -- Fields doc
602+ [(Name, Docstring (Either Err PTerm))] -- Param Docs
603+ [((Maybe Name), Plicity, t, Maybe (Docstring (Either Err PTerm)))] -- Fields
605604 (Maybe Name) -- Optional constructor name
606605 (Docstring (Either Err PTerm)) -- Constructor doc
607606 SyntaxInfo -- Constructor SyntaxInfo
@@ -707,8 +706,7 @@ declared (PData _ _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
707706declared (PData _ _ _ _ _ (PLaterdecl n _)) = [n]
708707declared (PParams _ _ ds) = concatMap declared ds
709708declared (PNamespace _ ds) = concatMap declared ds
710−declared (PRecord _ _ _ _ n ps _ fs _ cn _ _) = n : maybeToList cn -- : (map fstt ps) ++ (map fstt fs) ++ maybeToList cn
711− where fstt (a, _, _) = a
709+declared (PRecord _ _ _ _ n _ _ _ cn _ _) = n : maybeToList cn
712710declared (PClass _ _ _ _ n _ _ _ ms) = n : concatMap declared ms
713711declared (PInstance _ _ _ _ _ _ _ _ _ _) = []
714712declared (PDSL n _) = [n]
@@ -723,8 +721,7 @@ tldeclared (PFix _ _ _) = []
723721tldeclared (PTy _ _ _ _ _ n t) = [n]
724722tldeclared (PPostulate _ _ _ _ n t) = [n]
725723tldeclared (PClauses _ _ n _) = [] -- not a declaration
726−tldeclared (PRecord _ _ _ _ n ps _ fs _ cn _ _) = n : maybeToList cn -- (map fstt ps) ++ (map fstt fs) ++ maybeToList cn
727− where fstt (a, _, _) = a
724+tldeclared (PRecord _ _ _ _ n _ _ _ cn _ _) = n : maybeToList cn
728725tldeclared (PData _ _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
729726 where fstt (_, _, a, _, _, _) = a
730727tldeclared (PParams _ _ ds) = []
@@ -745,8 +742,7 @@ defined (PData _ _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
745742defined (PData _ _ _ _ _ (PLaterdecl n _)) = []
746743defined (PParams _ _ ds) = concatMap defined ds
747744defined (PNamespace _ ds) = concatMap defined ds
748−defined (PRecord _ _ _ _ n ps _ fs _ cn _ _) = n : maybeToList cn -- (map fstt ps) ++ (map fstt fs) ++ maybeToList cn
749− where fstt (a, _, _) = a
745+defined (PRecord _ _ _ _ n _ _ _ cn _ _) = n : maybeToList cn
750746defined (PClass _ _ _ _ n _ _ _ ms) = n : concatMap defined ms
751747defined (PInstance _ _ _ _ _ _ _ _ _ _) = []
752748defined (PDSL n _) = [n]
src/Idris/DeepSeq.hs+2−2
@@ -144,11 +144,11 @@ instance (NFData t) => NFData (PDecl' t) where
144144 rnf x3 `seq` rnf x4 `seq` rnf x5 `seq` rnf x6 `seq` ()
145145 rnf (PParams x1 x2 x3) = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` ()
146146 rnf (PNamespace x1 x2) = rnf x1 `seq` rnf x2 `seq` ()
147− rnf (PRecord x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12)
147+ rnf (PRecord x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11)
148148 = rnf x1 `seq`
149149 rnf x2 `seq`
150150 rnf x3 `seq`
151− rnf x4 `seq` rnf x5 `seq` rnf x6 `seq` rnf x7 `seq` rnf x8 `seq` rnf x9 `seq` rnf x10 `seq` rnf x11 `seq` rnf x12 `seq` ()
151+ rnf x4 `seq` rnf x5 `seq` rnf x6 `seq` rnf x7 `seq` rnf x8 `seq` rnf x9 `seq` rnf x10 `seq` rnf x11 `seq` ()
152152 rnf (PClass x1 x2 x3 x4 x5 x6 x8 x7 x9)
153153 = rnf x1 `seq`
154154 rnf x2 `seq`
src/Idris/Elab/Record.hs+109−45
@@ -15,7 +15,7 @@ import Data.Maybe
1515import Data.List
1616import Control.Monad
1717
18−elabRecord :: ElabInfo ->
18+elabRecord :: ElabInfo ->
1919 (Docstring (Either Err PTerm)) ->
2020 SyntaxInfo ->
2121 FC ->
@@ -23,13 +23,12 @@ elabRecord :: ElabInfo ->
2323 Name -> -- ^ Record Type Name
2424 [(Name, Plicity, PTerm)] -> -- ^ Parameters
2525 [(Name, Docstring (Either Err PTerm))] -> -- ^ Parameter Docs
26− [(Name, Plicity, PTerm)] -> -- ^ Fields
27− [(Name, Docstring (Either Err PTerm))] -> -- ^ Field Docs
26+ [((Maybe Name), Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> -- ^ Fields
2827 Maybe Name -> -- ^ Constructor Name
2928 (Docstring (Either Err PTerm)) -> -- ^ Constructor Doc
3029 SyntaxInfo -> -- ^ Constructor SyntaxInfo
3130 Idris ()
32−elabRecord info doc rsyn fc opts tyn params paramDocs fields fieldDocs cname cdoc csyn
31+elabRecord info doc rsyn fc opts tyn params paramDocs fields cname cdoc csyn
3332 = do logLvl 1 $ "Building data declaration for " ++ show tyn
3433 -- Type constructor
3534 let tycon = generateTyConType params
@@ -37,16 +36,105 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields fieldDocs cname cdo
3736
3837 -- Data constructor
3938 dconName <- generateDConName cname
40− let dconTy = generateDConType params fields
39+ let dconTy = generateDConType params fieldsWithNameAndDoc
4140 logLvl 1 $ "Data constructor: " ++ showTmImpls dconTy
42−
41+
4342 -- Build data declaration for elaboration
44− let datadecl = PDatadecl tyn tycon [(cdoc, [], dconName, dconTy, fc, [])]
45− elabData info rsyn doc [] fc opts datadecl
43+ let datadecl = PDatadecl tyn tycon [(cdoc, dconsArgDocs, dconName, dconTy, fc, [])]
44+ elabData info rsyn doc paramDocs fc opts datadecl
45+
46+ iLOG $ "fieldsWithName " ++ show fieldsWithName
47+ iLOG $ "fieldsWIthNameAndDoc " ++ show fieldsWithNameAndDoc
48+ elabRecordFunctions info rsyn fc tyn paramsAndDoc fieldsWithNameAndDoc dconName target
49+ where
50+ -- | Generates a type constructor.
51+ generateTyConType :: [(Name, Plicity, PTerm)] -> PTerm
52+ generateTyConType ((n, p, t) : rest) = PPi p (nsroot n) t (generateTyConType rest)
53+ generateTyConType [] = PType
4654
47− i <- getIState
55+ -- | Generates a name for the data constructor if none was specified.
56+ generateDConName :: Maybe Name -> Idris Name
57+ generateDConName (Just n) = return $ expandNS csyn n
58+ generateDConName Nothing = uniqueName (expandNS csyn $ sMN 0 ("Mk" ++ (show (nsroot tyn))))
59+ where
60+ uniqueName :: Name -> Idris Name
61+ uniqueName n = do i <- getIState
62+ case lookupTyNameExact n (tt_ctxt i) of
63+ Just _ -> uniqueName (nextName n)
64+ Nothing -> return n
65+
66+ -- | Generates the data constructor type.
67+ generateDConType :: [(Name, Plicity, PTerm)] -> [(Name, Plicity, PTerm, a)] -> PTerm
68+ generateDConType ((n, _, t) : ps) as = PPi impl (nsroot n) t (generateDConType ps as)
69+ generateDConType [] ((n, p, t, _) : as) = PPi p (nsroot n) t (generateDConType [] as)
70+ generateDConType [] [] = target
71+
72+ -- | The target for the constructor and projection functions. Also the source of the update functions.
73+ target :: PTerm
74+ target = PApp fc (PRef fc tyn) $ map (uncurry asPRefArg) [(p, n) | (n, p, _) <- params]
75+
76+ paramsAndDoc :: [(Name, Plicity, PTerm, Docstring (Either Err PTerm))]
77+ paramsAndDoc = pad params paramDocs
78+ where
79+ pad :: [(Name, Plicity, PTerm)] -> [(Name, Docstring (Either Err PTerm))] -> [(Name, Plicity, PTerm, Docstring (Either Err PTerm))]
80+ pad ((n, p, t) : rest) docs
81+ = let d = case lookup n docs of
82+ Just d' -> d
83+ Nothing -> emptyDocstring
84+ in (n, p, t, d) : (pad rest docs)
85+ pad _ _ = []
86+
87+ dconsArgDocs :: [(Name, Docstring (Either Err PTerm))]
88+ dconsArgDocs = paramDocs ++ (dcad fieldsWithName)
89+ where
90+ dcad :: [(Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, Docstring (Either Err PTerm))]
91+ dcad ((n, _, _, (Just d)) : rest) = (n, d) : (dcad rest)
92+ dcad (_ : rest) = dcad rest
93+ dcad [] = []
94+
95+ fieldsWithName :: [(Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))]
96+ fieldsWithName = fwn [] fields
97+ where
98+ fwn :: [Name] -> [(Maybe Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))]
99+ fwn ns ((n, p, t, d) : rest)
100+ = let nn = case n of
101+ Just n' -> n'
102+ Nothing -> newName ns baseName
103+ in (expandNS rsyn $ nn, p, t, d) : (fwn (nn : ns) rest)
104+ fwn _ _ = []
105+
106+ baseName = sUN "__pi_arg"
107+
108+ newName :: [Name] -> Name -> Name
109+ newName ns n
110+ | n `elem` ns = newName ns (nextName n)
111+ | otherwise = n
112+
113+ fieldsWithNameAndDoc :: [(Name, Plicity, PTerm, Docstring (Either Err PTerm))]
114+ fieldsWithNameAndDoc = fwnad fieldsWithName
115+ where
116+ fwnad :: [(Name, Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))] -> [(Name, Plicity, PTerm, Docstring (Either Err PTerm))]
117+ fwnad ((n, p, t, d) : rest)
118+ = let doc = fromMaybe emptyDocstring d
119+ in (n, p, t, doc) : (fwnad rest)
120+ fwnad [] = []
48121
122+elabRecordFunctions :: ElabInfo ->
123+ SyntaxInfo ->
124+ FC ->
125+ Name -> -- ^ Record Type Name
126+ [(Name, Plicity, PTerm, Docstring (Either Err PTerm))] -> -- ^ Parameters
127+ [(Name, Plicity, PTerm, Docstring (Either Err PTerm))]-> -- ^ Fields
128+ Name -> -- ^ Constructor Name
129+ PTerm -> -- ^ Target Type
130+ Idris ()
131+elabRecordFunctions info rsyn fc tyn params fields dconName target
132+ = do logLvl 1 $ "Elaborating helper functions for record " ++ show tyn
133+
134+ iLOG $ "Fields: " ++ show fieldNames
135+ iLOG $ "Params: " ++ show paramNames
49136 -- The elaborated constructor type for the data declaration
137+ i <- getIState
50138 ttConsTy <-
51139 case lookupTyExact dconName (tt_ctxt i) of
52140 Just as -> return as
@@ -54,15 +142,17 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields fieldDocs cname cdo
54142
55143 -- The arguments to the constructor
56144 let constructorArgs = getArgTys ttConsTy
145+ iLOG $ "Cons args: " ++ show constructorArgs
146+ iLOG $ "Free fields: " ++ show (filter (not . isFieldOrParam') constructorArgs)
57147 -- If elaborating the constructor has resulted in some new implicit fields we make projection functions for them.
58148 let freeFieldsForElab = map (freeField i) (filter (not . isFieldOrParam') constructorArgs)
59149
60150 -- The parameters for elaboration with their documentation
61151 -- Parameter functions are all prefixed with "param_".
62− let paramsForElab = [((nsroot n), (paramName n), impl, t, d) | (n, t, d) <- zipParams i params paramDocs]
152+ let paramsForElab = [((nsroot n), (paramName n), impl, t, d) | (n, _, t, d) <- params] -- zipParams i params paramDocs]
63153
64154 -- The fields (written by the user) with their documentation.
65− let userFieldsForElab = [((nsroot n), n, p, t, d) | ((n, p, t), (_, d)) <- zip fields fieldDocs]
155+ let userFieldsForElab = [((nsroot n), n, p, t, d) | (n, p, t, d) <- fields]
66156
67157 -- All things we need to elaborate projection functions for, together with a number denoting their position in the constructor.
68158 let projectors = [(n, n', p, t, d, i) | ((n, n', p, t, d), i) <- zip (freeFieldsForElab ++ paramsForElab ++ userFieldsForElab) [0..]]
@@ -78,46 +168,16 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields fieldDocs cname cdo
78168 -- Build and elaborate update functions
79169 elabUp dconName updaters
80170 where
81− -- | Generates a type constructor.
82− generateTyConType :: [(Name, Plicity, PTerm)] -> PTerm
83− generateTyConType ((n, p, t) : rest) = PPi p (nsroot n) t (generateTyConType rest)
84− generateTyConType [] = PType
85−
86− -- | Generates a name for the data constructor if none was specified.
87− generateDConName :: Maybe Name -> Idris Name
88− generateDConName (Just n) = return $ expandNS csyn n
89− generateDConName Nothing = uniqueName (expandNS csyn $ sMN 0 ("Mk" ++ (show (nsroot tyn))))
90− where
91− uniqueName :: Name -> Idris Name
92− uniqueName n = do i <- getIState
93− case lookupTyNameExact n (tt_ctxt i) of
94− Just _ -> uniqueName (nextName n)
95− Nothing -> return n
96−
97− -- | Generates the data constructor type.
98− generateDConType :: [(Name, Plicity, PTerm)] -> [(Name, Plicity, PTerm)] -> PTerm
99− generateDConType ((n, _, t) : ps) as = PPi impl (nsroot n) t (generateDConType ps as)
100− generateDConType [] ((n, p, t) : as) = PPi p (nsroot n) t (generateDConType [] as)
101− generateDConType [] [] = target
102−
103− -- | Creates an PArg from a plicity and a name where the term is a PRef.
104− asPRefArg :: Plicity -> Name -> PArg
105− asPRefArg p n = asArg p (nsroot n) $ PRef fc (nsroot n)
106−
107− -- | The target for the constructor and projection functions. Also the source of the update functions.
108− target :: PTerm
109− target = PApp fc (PRef fc tyn) $ map (uncurry asPRefArg) [(p, n) | (n, p, t) <- params]
110−
111171 -- | Creates a PArg from a plicity and a name where the term is a Placeholder.
112172 placeholderArg :: Plicity -> Name -> PArg
113173 placeholderArg p n = asArg p (nsroot n) Placeholder
114174
115175 -- | Root names of all fields in the current record declarations
116176 fieldNames :: [Name]
117− fieldNames = [nsroot n | (n, _, _) <- fields]
177+ fieldNames = [nsroot n | (n, _, _, _) <- fields]
118178
119179 paramNames :: [Name]
120− paramNames = [nsroot n | (n, _, _) <- params]
180+ paramNames = [nsroot n | (n, _, _, _) <- params]
121181
122182 isFieldOrParam :: Name -> Bool
123183 isFieldOrParam n = n `elem` (fieldNames ++ paramNames)
@@ -132,7 +192,7 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields fieldDocs cname cdo
132192 isField' (n, _, _, _, _, _) = isField n
133193
134194 fieldTerms :: [PTerm]
135− fieldTerms = [t | (_, _, t) <- fields]
195+ fieldTerms = [t | (_, _, t, _) <- fields]
136196
137197 -- Delabs the TT to PTerm
138198 -- This is not good.
@@ -186,7 +246,7 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields fieldDocs cname cdo
186246
187247 -- | A map from a field name to the other fields it depends on.
188248 fieldDependencies :: [(Name, [Name])]
189− fieldDependencies = map (uncurry fieldDep) [(n, t) | (n, _, t) <- fields ++ params]
249+ fieldDependencies = map (uncurry fieldDep) [(n, t) | (n, _, t, _) <- fields ++ params]
190250 where
191251 fieldDep :: Name -> PTerm -> (Name, [Name])
192252 fieldDep n t = ((nsroot n), paramNames ++ fieldNames `intersect` allNamesIn t)
@@ -363,3 +423,7 @@ projectInType xs = mapPT st
363423 st (PRef fc n)
364424 | Just pn <- lookup n xs = PApp fc (PRef fc pn) [pexp recRef]
365425 st t = t
426+
427+-- | Creates an PArg from a plicity and a name where the term is a PRef.
428+asPRefArg :: Plicity -> Name -> PArg
429+asPRefArg p n = asArg p (nsroot n) $ PRef emptyFC (nsroot n)
src/Idris/ElabDecls.hs+2−2
@@ -236,10 +236,10 @@ elabDecl' what info (PClass doc s f cs n ps pdocs fds ds)
236236elabDecl' what info (PInstance doc argDocs s f cs n ps t expn ds)
237237 = do iLOG $ "Elaborating instance " ++ show n
238238 elabInstance info s doc argDocs what f cs n ps t expn ds
239−elabDecl' what info (PRecord doc rsyn fc opts name ps pdocs fs fdocs cname cdoc csyn)
239+elabDecl' what info (PRecord doc rsyn fc opts name ps pdocs fs cname cdoc csyn)
240240 | what /= ETypes
241241 = do iLOG $ "Elaborating record " ++ show name
242− elabRecord info doc rsyn fc opts name ps pdocs fs fdocs cname cdoc csyn
242+ elabRecord info doc rsyn fc opts name ps pdocs fs cname cdoc csyn
243243{-
244244 | otherwise
245245 = do iLOG $ "Elaborating [type of] " ++ show tyn
src/Idris/IBC.hs+2−4
@@ -1227,7 +1227,7 @@ instance (Binary t) => Binary (PDecl' t) where
12271227 PNamespace x1 x2 -> do putWord8 5
12281228 put x1
12291229 put x2
1230− PRecord x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 ->
1230+ PRecord x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 ->
12311231 do putWord8 6
12321232 put x1
12331233 put x2
@@ -1240,7 +1240,6 @@ instance (Binary t) => Binary (PDecl' t) where
12401240 put x9
12411241 put x10
12421242 put x11
1243− put x12
12441243 PClass x1 x2 x3 x4 x5 x6 x7 x8 x9
12451244 -> do putWord8 7
12461245 put x1
@@ -1343,8 +1342,7 @@ instance (Binary t) => Binary (PDecl' t) where
13431342 x9 <- get
13441343 x10 <- get
13451344 x11 <- get
1346− x12 <- get
1347− return (PRecord x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12)
1345+ return (PRecord x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11)
13481346 7 -> do x1 <- get
13491347 x2 <- get
13501348 x3 <- get
src/Idris/ParseData.hs+15−13
@@ -37,8 +37,6 @@ import qualified Data.ByteString.UTF8 as UTF8
3737
3838import Debug.Trace
3939
40−type Docs = Docstring (Either Err PTerm)
41−
4240{- |Parses a record type declaration
4341Record ::=
4442 DocComment Accessibility? 'record' FnName TypeSig 'where' OpenBlock Constructor KeepTerminator CloseBlock;
@@ -60,11 +58,11 @@ record syn = do (doc, paramDocs, acc, opts) <- try (do
6058 let rsyn = syn { syn_namespace = show (nsroot tyn) :
6159 syn_namespace syn }
6260 params <- manyTill (recordParameter rsyn) (reserved "where")
63− (fields, fieldDocs, cname, cdoc) <- indentedBlockS $ agdaStyleBody rsyn tyn
61+ (fields, cname, cdoc) <- indentedBlockS $ agdaStyleBody rsyn tyn
6462 case cname of
6563 Just cn' -> accData acc tyn [cn']
6664 Nothing -> return ()
67− return $ PRecord doc rsyn fc opts tyn params paramDocs fields fieldDocs cname cdoc syn
65+ return $ PRecord doc rsyn fc opts tyn params paramDocs fields cname cdoc syn
6866 <?> "record type declaration"
6967 where
7068 getRecNames :: SyntaxInfo -> PTerm -> [Name]
@@ -76,7 +74,7 @@ record syn = do (doc, paramDocs, acc, opts) <- try (do
7674 toFreeze (Just Frozen) = Just Hidden
7775 toFreeze x = x
7876
79− agdaStyleBody :: SyntaxInfo -> Name -> IdrisParser ([(Name, Plicity, PTerm)], [(Name, Docs)], Maybe Name, Docs)
77+ agdaStyleBody :: SyntaxInfo -> Name -> IdrisParser ([((Maybe Name), Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))], Maybe Name, Docstring (Either Err PTerm))
8078 agdaStyleBody syn tyn = do
8179 ist <- get
8280 fc <- getFC
@@ -89,20 +87,24 @@ record syn = do (doc, paramDocs, acc, opts) <- try (do
8987 let constructorDoc' = annotate syn ist constructorDoc
9088
9189 fields <- many . indented $ field syn
92−
93− let fieldDocs = [(n, annotate syn ist doc) | (n, _, _, doc) <- fields]
94− let fields' = [(n, p, t) | (n, t, p, _) <- fields]
9590
96− return (fields', fieldDocs, constructorName, constructorDoc')
91+ return (fields, constructorName, constructorDoc')
9792 where
98− field :: SyntaxInfo -> IdrisParser (Name, PTerm, Plicity, Docstring ())
99− field syn = do (doc, _) <- option noDocs docComment
93+ field :: SyntaxInfo -> IdrisParser ((Maybe Name), Plicity, PTerm, Maybe (Docstring (Either Err PTerm)))
94+ field syn = do doc <- optional docComment
10095 c <- optional $ lchar '{'
101− n <- fnName <|> do symbol "_"; return $ sUN "__pi_arg"
96+ n <- (do n <- fnName
97+ return $ Just (expandNS syn n))
98+ <|> (do symbol "_"
99+ return Nothing)
102100 lchar ':'
103101 t <- typeExpr (allowImp syn)
104102 p <- endPlicity c
105− return (expandNS syn n, t, p, doc)
103+ ist <- get
104+ let doc' = case doc of
105+ Just (d,_) -> Just $ annotate syn ist d
106+ Nothing -> Nothing
107+ return (n, p, t, doc')
106108
107109 constructor :: IdrisParser Name
108110 constructor = (reserved "constructor") *> fnName