Commit d2332fe0 authored by Camil Staps's avatar Camil Staps 🍃

Support multiline documentation for constructors by using several single-line comments

parent 05eccbb9
......@@ -12,13 +12,16 @@ import StdString
import StdTuple
import Control.Monad
import Data.Bifunctor
import Data.Error
from Data.Func import $
import Data.Functor
from Data.Map import :: Map(..), newMap, put, get
from Data.Map import :: Map(..), newMap, put, get, alter
import Data.Maybe
import Data.Tuple
import System.File
import System.FilePath
from Text import class Text(startsWith), instance Text String
from Text import class Text(concat,startsWith), instance Text String
from Heap import :: Heap, :: HeapN, :: Ptr{pointer}, :: PtrN(Ptr), readPtr
from syntax import
......@@ -244,8 +247,17 @@ collectComments comments pm
[c:cs]
| c.line <= 3 && startsWith "*" c.content -> (cs, putCC pm c coll)
| otherwise -> (comments, coll)
# comments = chunkSingleLineComments comments
# (_,_,coll) = collect comments Nothing pm.mod_defs coll
= coll
where
chunkSingleLineComments [] = []
chunkSingleLineComments [c:cs]
| c.multiline = [c:chunkSingleLineComments cs]
# (same,rest) = bifmap (map snd) (map snd) $ span
(\(i,c`) -> i==c`.line && c.column==c`.column)
[(i,c`) \\ c` <- cs & i <- [c.line+1..]]
= [{c & content=concat [c`.content \\ c` <- [c:same]]}:chunkSingleLineComments rest]
collect :: ![CleanComment] !(Maybe CleanComment) ![a] !CollectedComments -> (![CleanComment], !Maybe CleanComment, !CollectedComments) | pos, singleLineAbove, commentIndex, children a
collect cc prev [] coll = (cc, prev, coll)
......
......@@ -18,7 +18,11 @@ import Clean.Parse.Comments
//* This type is just here to test; it isn't used
:: TrickyADT
= TrickyADT_A
= TrickyADT_A //* Documentation on same line
| TrickyADT_B
//* Documentation on new line
//* Extra documentation line
| TrickyADT_C
//* Documentation on new line
list_comments :: !ParsedModule !CollectedComments -> [Entry]
......
......@@ -37,7 +37,9 @@ expected =
, {kind="selector", name="name", value=Just "* the name of the documented thing\n"}
, {kind="selector", name="value", value=Nothing}
, {kind="type", name="TrickyADT", value=Just "* This type is just here to test; it isn't used\n"}
, {kind="constructor", name="TrickyADT_A", value=Just "* Documentation on new line\n"}
, {kind="constructor", name="TrickyADT_A", value=Just "* Documentation on same line\n"}
, {kind="constructor", name="TrickyADT_B", value=Just "* Documentation on new line\n* Extra documentation line\n"}
, {kind="constructor", name="TrickyADT_C", value=Just "* Documentation on new line\n"}
, {kind="typespec", name="list_comments", value=Nothing}
]
......
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