Commit a8e55c48 authored by Björn Peemöller 's avatar Björn Peemöller
Browse files

currydoc: Incorporated changes from Sandra Dylus

parent 8ddb2dec
......@@ -31,6 +31,7 @@ import CurryDocParams
import CurryDocRead
import CurryDocHtml
import CurryDocTeX
import CurryDocCDoc
import FlatCurry
import System
import Time
......@@ -67,6 +68,8 @@ processArgs docparams args = do
processArgs (setDocType HtmlDoc docparams) margs
("--tex":margs) ->
processArgs (setDocType TexDoc docparams) margs
("--cdoc":margs) ->
processArgs (setDocType CDoc docparams) margs
["--noindexhtml",docdir,modname] ->
makeCompleteDoc (setIndex False (setDocType HtmlDoc docparams))
True docdir (stripSuffix modname)
......@@ -107,7 +110,8 @@ makeCompleteDoc docparams recursive docdir modname = do
prepareDocDir (docType docparams) docdir
-- parsing source program:
callFrontend FCY modname
(alltypes,allfuns,allops) <- readFlatCurryWithImports [modname]
-- when constructing CDOC the imported modules don't have to be read from the flatCurryFile
(alltypes, allfuns, allops) <- getProg $ docType docparams
progname <- findSourceFileInLoadPath modname
makeDocIfNecessary docparams recursive docdir
(genAnaInfo (Prog modname [] alltypes allfuns allops))
......@@ -121,6 +125,12 @@ makeCompleteDoc docparams recursive docdir modname = do
-- change access rights to readable for everybody:
system ("chmod -R go+rX "++docdir)
done
where getProg HtmlDoc = readFlatCurryWithImports [modname]
getProg TexDoc = readFlatCurryWithImports [modname]
getProg CDoc = do
Prog _ _ t f o <- readFlatCurry modname
return (t, f, o)
--- Generate only the index pages for a list of (already compiled!) modules:
makeIndexPages :: String -> [String] -> IO ()
......@@ -149,6 +159,9 @@ prepareDocDir TexDoc docdir = do
createDir docdir
putStrLn $ "Copy macros into documentation directory \""++docdir++"\"..."
copyIncludeIfPresent docdir "currydoc.tex"
prepareDocDir CDoc docdir = do
createDir docdir
putStrLn ("Directory was created succesfully")
copyIncludeIfPresent docdir inclfile = do
existIDir <- doesDirectoryExist includeDir
......@@ -174,25 +187,20 @@ makeDoc docparams recursive docdir anainfo progname = do
makeDocWithComments HtmlDoc docparams recursive docdir anainfo progname
modcmts progcmts = do
time <- getLocalTime
(imports,hexps) <- generateHtmlDocs currydocVersion time docparams anainfo
progname modcmts progcmts
let outfile = docdir++"/"++getLastName progname++".html"
putStrLn $ "Writing documentation to \""++outfile++"\"..."
writeFile outfile (showDocCSS ("Module "++getLastName progname) hexps)
writeOutfile docparams recursive docdir anainfo progname (generateHtmlDocs
currydocVersion time docparams anainfo progname modcmts progcmts)
translateSource2ColoredHtml docdir progname
if recursive
then mapIO_ (makeDocIfNecessary docparams recursive docdir anainfo) imports
else done
writeOutfile (DocParams CDoc False False) False docdir anainfo progname (generateCDoc progname modcmts progcmts anainfo)
makeDocWithComments TexDoc docparams recursive docdir anainfo progname
modcmts progcmts = do
(imports,textxt) <- generateTexDocs docparams anainfo progname modcmts progcmts
let outfile = docdir++"/"++getLastName progname++".tex"
putStrLn $ "Writing documentation to \""++outfile++"\"..."
writeFile outfile textxt
if recursive
then mapIO_ (makeDocIfNecessary docparams recursive docdir anainfo) imports
else done
writeOutfile docparams recursive docdir anainfo progname (generateTexDocs docparams anainfo progname modcmts progcmts)
makeDocWithComments CDoc docparams recursive docdir anainfo progname
modcmts progcmts = do
writeOutfile docparams recursive docdir anainfo progname (generateCDoc progname modcmts progcmts anainfo)
--- Generates the documentation for a module if it is necessary.
......@@ -290,4 +298,22 @@ findSourceFileInLoadPath modname = do
(return . stripSuffix)
mbfname
-----------------------------------------------------------------------
-- get the associated file extenstion from DocType
fileExtension :: DocType -> String
fileExtension HtmlDoc = "html"
fileExtension TexDoc = "tex"
fileExtension CDoc = "cdoc"
-- harmonized writeFile function for all docType
writeOutfile :: DocParams -> Bool -> String -> AnaInfo -> String -> IO String -> IO ()
writeOutfile docparams recursive docdir anainfo progname generate = do
doc <- generate
imports <- getImports progname
let outfile = docdir++"/"++getLastName progname++"."++fileExtension (docType docparams)
putStrLn ("Writing documentation to \""++outfile++"\"...")
writeFile outfile doc
if recursive
then mapIO_ (makeDocIfNecessary docparams recursive docdir anainfo) imports
else done
-- -----------------------------------------------------------------------
\ No newline at end of file
----------------------------------------------------------------------
--- Functions to generate documentation in "CDoc" format.
---
--- @author Sandra Dylus
----------------------------------------------------------------------
module CurryDocCDoc where
import CurryDocParams
import CurryDocRead
import FlatCurry
import FlexRigid
import ReadShowTerm
import List
generateCDoc :: String -> String -> [(SourceLine,String)] -> AnaInfo -> IO String
generateCDoc progName modCmts progCmts anaInfo = do
Prog modName _ types functions _ <- readFlatCurryFile fcyName
let modInfo = ModuleInfo modName (author avCmts) mCmts
funcInfo (Func qName@(mName, fName) _ _ tExpr rule) =
FunctionInfo fName
tExpr
mName
(funcComment fName progCmts)
(getOverlappingInfo anaInfo qName)
(flexRigid rule)
typeInfo (Type (mName, tName) _ vars consDecl) =
TypeInfo tName
(map consSignature (filter (\(Cons _ _ vis _) -> vis == Public) consDecl))
vars
mName
(dataComment tName progCmts)
False
typeInfo (TypeSyn qName@(mName, tName) _ vars tExpr) =
TypeInfo tName
[(qName, [tExpr])]
vars
mName
(dataComment tName progCmts)
True
(mCmts, avCmts) = splitComment modCmts
funcInfos = map funcInfo (filter (\(Func _ _ vis _ _) -> vis == Public) functions)
typeInfos = map typeInfo (concatMap filterT types)
putStrLn $ "Writing " ++ modName ++ ".cdoc file"
return $ showTerm (CurryInfo modInfo funcInfos typeInfos)
where fcyName = flatCurryFileName progName
filterT f@(Type _ vis _ _) = if vis == Public then [f] else []
filterT f@(TypeSyn _ vis _ _) = if vis == Public then [f] else []
funcComment :: String -> [(SourceLine,String)] -> String
funcComment str = fst . splitComment . getFuncComment str
dataComment :: String -> [(SourceLine,String)] -> String
dataComment str = fst . splitComment . getDataComment str
flexRigid :: Rule -> FlexRigidResult
flexRigid (Rule _ expr) = getFlexRigid expr
flexRigid (External _) = UnknownFR
-- the name
-- the author
-- the description
data ModuleInfo = ModuleInfo String String String
-- the module
-- the corresponding functions
-- the corresponding data and type declaration
data CurryInfo = CurryInfo ModuleInfo [FunctionInfo] [TypeInfo]
-- the name
-- the signature
-- the corresponding module
-- the description
-- True if property ist defined non-deterministically
-- the flex/rigid status
data FunctionInfo = FunctionInfo String TypeExpr String String Bool FlexRigidResult
-- the name
-- the signature (true indicates a type synonym, false a data type)
-- the corresponding module
-- the description
data TypeInfo = TypeInfo String [(QName, [TypeExpr])] [TVarIndex] String String Bool
-- auxilieres --------------------------------------------------------
author :: [(String, String)] -> String
author av = concat $ getCommentType "author" av
-- generate data and type constructors
consSignature :: ConsDecl -> (QName, [TypeExpr])
consSignature (Cons (mName, cName) _ _ tExprList) = ((mName, cName), tExprList)
......@@ -27,14 +27,13 @@ currydocCSS = "currydoc.css"
-- Generates the documentation of a module in HTML format where the comments
-- are already analyzed.
generateHtmlDocs :: String -> CalendarTime -> DocParams -> AnaInfo -> String
-> String -> [(SourceLine,String)] -> IO ([String],[HtmlExp])
-> String -> [(SourceLine,String)] -> IO String
generateHtmlDocs cdversion time docparams anainfo progname modcmts progcmts = do
let fcyname = flatCurryFileName progname
putStrLn $ "Reading FlatCurry program \""++fcyname++"\"..."
(Prog _ imports types functions ops) <- readFlatCurryFile fcyname
return $
(imports,
[h1 [href (getLastName progname++"_curry.html")
return
(showDocCSS ("Module"++getLastName progname) $ [h1 [href (getLastName progname++"_curry.html")
[htxt (getLastName progname++".curry")]]] ++
genHtmlModule docparams modcmts ++
[HtmlStruct "table" [("border","1"),("width","100%")]
......
......@@ -6,7 +6,7 @@ import System(system)
--------------------------------------------------------------------------
-- The kind of documentations which can be generated.
data DocType = HtmlDoc | TexDoc
data DocType = HtmlDoc | TexDoc | CDoc
-- The parameters for the documentation generator. Parameters:
-- doctype - the target format of the documentation
......
......@@ -19,23 +19,21 @@ import Markdown
-- Generates the documentation of a module in HTML format where the comments
-- are already analyzed.
generateTexDocs :: DocParams -> AnaInfo -> String -> String
-> [(SourceLine,String)] -> IO ([String],String)
-> [(SourceLine,String)] -> IO String
generateTexDocs docparams anainfo progname modcmts progcmts = do
let fcyname = flatCurryFileName progname
putStrLn $ "Reading FlatCurry program \""++fcyname++"\"..."
(Prog _ imports types functions _) <- readFlatCurryFile fcyname
(Prog _ _ types functions _) <- readFlatCurryFile fcyname
let textypes = concatMap (genTexType docparams progcmts) types
texfuncs = concatMap (genTexFunc docparams progcmts anainfo) functions
modcmt = fst (splitComment modcmts)
return $
(imports,
"\\currymodule{"++getLastName progname++"}\n" ++
htmlString2Tex docparams modcmt ++ "\n" ++
(if null textypes then ""
else "\\currytypesstart\n" ++ textypes ++ "\\currytypesstop\n") ++
(if null texfuncs then ""
else "\\curryfuncstart\n" ++ texfuncs ++ "\\curryfuncstop\n")
)
--- Translate a documentation comment to LaTeX and use markdown translation
--- if necessary. If the string contains HTML tags, these are also
......@@ -130,7 +128,6 @@ showTexType nested (TCons tc ts)
= brackets nested
(snd tc ++ " " ++ concat (intersperse " " (map (showTexType True) ts)))
-- convert string into TeX:
string2tex :: String -> String
string2tex = concatMap char2tex
......@@ -154,5 +151,3 @@ string2tex = concatMap char2tex
| c=='}' = "\\}"
| c=='&' = "\\&"
| otherwise = [c]
......@@ -4,31 +4,43 @@
# - installed Curry System (PAKCS or KiCS2) specified by variable CURRYSYSTEM
# - root location of the Curry System specified by variable ROOT
LIB=$(ROOT)/lib
META=$(LIB)/meta
ANADIR=../analysis
# directories
LIBDIR = $(ROOT)/lib
METADIR = $(LIBDIR)/meta
ANADIR = ../analysis
# binaries
REPL = $(ROOT)/bin/$(CURRYSYSTEM)
CLEANCURRY = $(ROOT)/bin/cleancurry
INSTALLBIN = $(ROOT)/bin/currydoc
# Source modules of currydoc:
DEPS = CurryDoc.curry CurryDocRead.curry CurryDocHtml.curry \
CurryDocTeX.curry CurryDocParams.curry \
$(LIB)/Markdown.curry \
$(META)/FlexRigid.curry \
$(LIB)/CategorizedHtmlList.curry \
$(LIB)/Distribution.curry $(LIB)/PropertyFile.curry \
$(META)/FlatCurry.curry \
$(LIB)/HTML.curry $(LIB)/HtmlParser.curry \
$(LIBDIR)/Markdown.curry \
$(METADIR)/FlexRigid.curry \
$(LIBDIR)/CategorizedHtmlList.curry \
$(LIBDIR)/Distribution.curry $(LIBDIR)/PropertyFile.curry \
$(METADIR)/FlatCurry.curry \
$(LIBDIR)/HTML.curry $(LIBDIR)/HtmlParser.curry \
$(ANADIR)/AnaOverlapping.curry $(ANADIR)/AnaIndeterminism.curry \
$(ANADIR)/AnaCompleteness.curry $(ANADIR)/AnaOpComplete.curry \
$(ANADIR)/AnaDependency.curry
$(ANADIR)/AnaDependency.curry
# generate saved PAKCS state for currydoc program:
CurryDoc: $(DEPS)
$(ROOT)/bin/$(CURRYSYSTEM) $(REPL_OPTS) :set path $(ANADIR) \
:l CurryDoc :save :q
(cd $(ROOT)/bin ; rm -f currydoc ; \
ln -s ../currytools/currydoc/CurryDoc currydoc)
.PHONY: install
install: CurryDoc
$(MAKE) uninstall
ln -s $< $(INSTALLBIN)
.PHONY: uninstall
uninstall:
rm -f $(INSTALLBIN)
.PHONY: clean
clean:
$(ROOT)/bin/cleancurry
rm -f $(ROOT)/bin/currydoc
clean:
$(CLEANCURRY)
rm -f CurryDoc
# generate saved PAKCS state for currydoc program:
CurryDoc: $(DEPS)
$(REPL) $(REPL_OPTS) :set path $(ANADIR) :load $@ :save :quit
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment