module Parse where import Prelude import Data.Traversable (scanr) import Data.List (List(Cons), (:)) data Loc = Loc { line :: Int } data LocRange = LocRange { start :: Loc, end :: Loc } data CommentNode = CommentBlock { value :: String, loc :: LocRange } | CommentLine { value :: String, loc :: LocRange } groupLineComments :: List CommentNode -> List CommentNode groupLineComments nodes = scanr appendComment nodes [] appendComment :: CommentNode -> List CommentNode -> List CommentNode appendComment (CommentBlock node) nodes = node : nodes appendComment (CommentLine node) (Cons first nodes) = (mergeComments first node) : nodes -- TODO: merge loc, too: mergeComments :: CommentNode -> CommentNode -> CommentNode -- mergeComments a b = CommentLine { value: a.value <> "\n" <> b.value, loc: a.loc } -- mergeComments a b = CommentLine (a.value <> "\n" <> b.value) a.loc -- mergeComments a b = CommentLine { value: a.value, loc: a.loc } mergeComments a b = a