@@ -1,275 +0,0 @@
14− { _exposed :: [A.Located Name.Name]
15− , _overview :: Utf8.String
16− , _listed :: [A.Located Name.Name]
17− , _comments :: Map.Map Name.Name Utf8.String
27− error "TODO implement docs parser"
30−chompUntilDocs :: Parser Bool
32− P.Parser $ \(P.State fp offset terminal indent row col ctx) cok _ _ _ ->
34− (# isStart, newOffset, newRow, newCol #) =
35− eatDocs fp offset terminal row col
38− P.State fp newOffset terminal indent newRow newCol ctx
43−eatDocs :: ForeignPtr Word8 -> Int -> Int -> Word16 -> Word16 -> (# Bool, Int, Word16, Word16 #)
44−eatDocs fp offset terminal row col =
45− if offset >= terminal then
46− (# False, offset, row, col #)
48− else if isDocsStart fp offset terminal then
49− (# True, offset + 5, row, col + 5 #)
52− let !word = P.unsafeIndex fp offset in
53− if word == 0x0A {- \n -} then
54− eatDocs fp (offset + 1) terminal (row + 1) 1
57− let !newOffset = offset + P.getCharWidth fp offset terminal word in
58− eatDocs fp newOffset terminal row (col + 1)
61−isDocsStart :: ForeignPtr Word8 -> Int -> Int -> Bool
63− let (B.PS dfp doff dlen) = docsStart in
64− P.isSubstring dfp doff dlen
67−{-# NOINLINE docsStart #-}
68−docsStart :: B.ByteString
73−chompOverview :: [A.Located Name.Name] -> Parser [A.Located Name.Name]
75− do isDocs <- chompUntilDocs
77− then chompOverviewHelp names
81−chompOverviewHelp :: [A.Located Name.Name] -> Parser [A.Located Name.Name]
82−chompOverviewHelp names =
83− do pos <- getPosition
84− (SPos spos) <- whitespace
86− then chompOverview names
87− else chompOverview =<< chompDocs names
90−chompDocs :: [A.Located Name.Name] -> Parser [A.Located Name.Name]
92− do name <- addLocation (oneOf SE.XXX [ Var.lower, Var.upper, chompBinop ])
96− word1 0x2C {-,-} SE.XXX
98− chompDocs (name:names)
99− , return (name:names)
103−chompBinop :: Parser Name.Name
105− do word1 0x28 {-(-} SE.XXX
106− name <- Symbol.binop
107− word1 0x29 {-)-} SE.XXX
117− Result.Result i w E.Error a
121− Map.Map Name.Name (OneOrMore.OneOrMore A.Region)
124−checkNames :: Map.Map Name.Name (A.Located Can.Export) -> [A.Located Name.Name] -> Result i w ()
125−checkNames exports names =
126− do docs <- Map.traverseWithKey isUnique (List.foldl' addName Map.empty names)
127− let overlap = Map.size (Map.intersection docs exports)
128− if Map.size exports == overlap && overlap == Map.size docs
131− do _ <- Map.traverseWithKey onlyInDocs (Map.difference docs exports)
132− _ <- Map.traverseWithKey onlyInExports (Map.difference exports docs)
136−addName :: Dups -> A.Located Name.Name -> Dups
137−addName dict (A.At region name) =
138− Map.insertWith OneOrMore.more name (OneOrMore.one region) dict
141−isUnique :: Name.Name -> OneOrMore.OneOrMore A.Region -> Result i w A.Region
142−isUnique name regions =
144− OneOrMore.One region ->
147− OneOrMore.More _ _ ->
148− let (r1:r2:_) = OneOrMore.toList regions in
149− Result.throw (E.Duplicate name r1 r2)
152−onlyInDocs :: Name.Name -> A.Region -> Result i w a
153−onlyInDocs name region =
154− Result.throw $ E.OnlyInDocs name region
157−onlyInExports :: Name.Name -> A.Located Can.Export -> Result i w a
158−onlyInExports name (A.At region _) =
159− Result.throw $ E.OnlyInExports name region
168− { _iComments :: Map.Map Name.Name Comment
170− , _iUnions :: Map.Map Name.Name Can.Union
171− , _iAliases :: Map.Map Name.Name Can.Alias
172− , _iBinops :: Map.Map Name.Name Can.Binop
173− , _iEffects :: Can.Effects
177−checkExport :: Info -> Name.Name -> A.Located Can.Export -> Result i w (Module -> Module)
178−checkExport info name (A.At region export) =
181− do tipe <- getType name info
182− comment <- getComment region name info
184− m { _values = Map.insert name (Value comment tipe) (_values m) }
187− do let (Can.Binop_ assoc prec realName) = _iBinops info ! name
188− tipe <- getType realName info
189− comment <- getComment region realName info
191− m { _binops = Map.insert name (Binop comment tipe assoc prec) (_binops m) }
194− do let (Can.Alias tvars tipe) = _iAliases info ! name
195− comment <- getComment region name info
197− m { _aliases = Map.insert name (Alias comment tvars (Extract.fromType tipe)) (_aliases m) }
199− Can.ExportUnionOpen ->
200− do let (Can.Union tvars ctors _ _) = _iUnions info ! name
201− comment <- getComment region name info
203− m { _unions = Map.insert name (Union comment tvars (map dector ctors)) (_unions m) }
205− Can.ExportUnionClosed ->
206− do let (Can.Union tvars _ _ _) = _iUnions info ! name
207− comment <- getComment region name info
209− m { _unions = Map.insert name (Union comment tvars []) (_unions m) }
212− do tipe <- getType name info
213− comment <- getComment region name info
215− m { _values = Map.insert name (Value comment tipe) (_values m) }
218−getComment :: A.Region -> Name.Name -> Info -> Result i w Comment
219−getComment region name info =
220− case Map.lookup name (_iComments info) of
222− Result.throw (E.NoComment name region)
228−getType :: Name.Name -> Info -> Result i w Type.Type
230− case _iValues info ! name of
231− A.At defRegion Nothing ->
232− Result.throw (E.NoAnnotation name defRegion)
234− A.At _ (Just tipe) ->
235− Result.ok (Extract.fromType tipe)
238−dector :: Can.Ctor -> (Name.Name, [Type.Type])
239−dector (Can.Ctor name _ _ args) =
240− ( name, map Extract.fromType args )
248− Map.Map Name.Name (A.Located (Maybe Can.Type))
251−gatherTypes :: Can.Decls -> Types -> Types
252−gatherTypes decls types =
254− Can.Declare def subDecls ->
255− gatherTypes subDecls (addDef types def)
257− Can.DeclareRec defs subDecls ->
258− gatherTypes subDecls (List.foldl' addDef types defs)
260− Can.SaveTheEnvironment ->
264−addDef :: Types -> Can.Def -> Types
267− Can.Def (A.At region name) _ _ ->
268− Map.insert name (A.At region Nothing) types
270− Can.TypedDef (A.At region name) _ typedArgs _ resultType ->
273− foldr Can.TLambda resultType (map snd typedArgs)
275− Map.insert name (A.At region (Just tipe)) types