Verified Commit 8855eac5 authored by Camil Staps's avatar Camil Staps 🚀

Add documentation of class members to string representation of classes (#5)

parent 7e8f1b69
Pipeline #15078 passed with stage
in 1 minute and 7 seconds
......@@ -5,6 +5,7 @@ import StdChar
import StdFile
import StdFunctions
import StdInt
import StdList
import StdMisc
import StdString
......@@ -14,14 +15,15 @@ import Clean.Parse
import Clean.Parse.Comments
from Clean.PrettyPrint import class cpp(cpp), instance cpp ParsedDefinition
import Control.Applicative
import Control.Monad
import Control.Monad => qualified join
import Data.Either
import Data.Error
from Data.Func import instance Functor ((->) a)
from Data.Func import $, instance Functor ((->) a)
import Data.Functor
import Data.Maybe
import Data.Tuple
import System.File
import Text
from syntax import
:: ClassDef{class_ident,class_pos},
......@@ -109,14 +111,29 @@ where
collectClass cc pd=:(PD_Class cd members) =
{ name = cd.class_ident.id_name
, pos = position (Just pd) Nothing
, repr = Just (cpp pd)
, elem =
{ class_members = [collectFunction cc m \\ m <- members]
}
, repr = Just $ intersperseDoc [m.doc \\ m <- mems] $ cpp pd
, elem = {class_members=mems}
, doc = case parseDoc <$> getComment pd cc of
Just (Right (doc,_)) -> Just doc
_ -> Nothing
}
where
mems = map (collectFunction cc) [pd \\ pd=:(PD_TypeSpec _ _ _ _ _) <- members]
intersperseDoc memdoc repr = case split "\n" repr of
[hd1,hd2:tl] -> join "\n"
[ hd1
, hd2
: [fromMaybe "" (printDoc <$> doc) +++ fun \\ fun <- tl & doc <- memdoc]
]
_ -> repr
printDoc doc = "\t/**\n\t * " +++ replaceSubString "\n" "\n\t * " (join "\n" $ catMaybes
[ docDescription doc
, ((+++) "@complexity ") <$> docComplexity doc
: [Just $ "@param " <+ p \\ p <- docParams doc]
++ [Just $ "@result " +++ r \\ r <- docResults doc]
++ [Just $ "@throws " +++ e \\ e <- docThrows doc]
]) +++ "\n\t */\n"
collectGeneric :: !CollectedComments !ParsedDefinition -> DescribedGeneric
collectGeneric cc pd=:(PD_Generic gd) =
......
......@@ -12,7 +12,7 @@ import StdTuple
import Clean.Doc => qualified :: ParamDoc{name}
import Clean.Types.Util
import Control.Applicative
import Control.Monad
import Control.Monad => qualified join
import Data.Error
from Data.Func import $, mapSt, instance Functor ((->) a)
import Data.Functor
......@@ -21,7 +21,7 @@ import System.Directory
import System.Environment
import System.File
import System.FilePath
import Text => qualified join
import Text
import Text.GenJSON
import Text.HTML
import Text.Language
......
......@@ -7,7 +7,7 @@ import StdTuple
import Clean.ModuleFinder
import Clean.Parse
import Data.Error
from Data.Func import $, mapSt
from Data.Func import $, hyperstrict, mapSt
import System.CommandLine
import System.Options
import Text
......@@ -56,7 +56,7 @@ Start w
# (modcoll,w) = mapSt (collectModule opts.module_finding_options) fps w
| any isError modcoll = exit [e \\ Error e <- modcoll] w
# modcoll = map fromOk modcoll
# modcoll = hyperstrict $ map fromOk modcoll
| isEmpty modcoll = exit ["No modules found"] w
# html = generateHTML modcoll
......
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