-- Parsec parser of tokenized XML obtained from TypEr output (tokenization made by Tagsoup). -- This parser, although working with different kind of XML than the Edoc XML parser, -- creates the same data structure as Edoc parser does, thus giving some chance -- to put them together in the future. module Language.Edoc.Xml2Hs.TyParser where import Text.HTML.TagSoup import Text.HTML.TagSoup.Parser import Text.HTML.TagSoup.Match import Text.HTML.TagSoup.Type import Text.ParserCombinators.Parsec import Text.ParserCombinators.Parsec.Pos import Language.Edoc.Xml2Hs.Type -- Import stuff from the Edoc parser as many of it can be reused. import Language.Edoc.Xml2Hs.Parser -- Parse a whole set of specifications. Currently the TypEr output does not -- contain module names, so assign a name from the argument. -- The input stream basically consists of type specifications only. -- So the parser just expects many type specifications each one -- describing a single function. pTyMod :: String -> GenParser Tag PState EDocMod pTyMod mname = do skipMany ignore fds <- many pSpec return $ EDocMod { em_name = mname ,em_args = [] ,em_tdefs = [] ,em_funcs = fds} -- Parse a function type declaration. pSpec = do fn <- expTag "spec" let arity = read $ fromAttrib "arity" fn ftyp <- pErlType closeTag "spec" return $ EFunDecl { ef_name = fromAttrib "function" fn ,ef_arity = arity ,ef_args = map (('_':) . show) (take arity [1 .. ]) ,ef_tspec = [ETypeSpec { ts_ename = ErlName "" "" "" ,ts_type = ftyp ,ts_ldef = []}]}