Skip to content

Instantly share code, notes, and snippets.

@unscriptable
Created June 13, 2016 14:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unscriptable/29b5c8c88ef1f27df0567ff104cec810 to your computer and use it in GitHub Desktop.
Save unscriptable/29b5c8c88ef1f27df0567ff104cec810 to your computer and use it in GitHub Desktop.
simple purescript that dont werk
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment