Created
June 13, 2016 14:35
-
-
Save unscriptable/29b5c8c88ef1f27df0567ff104cec810 to your computer and use it in GitHub Desktop.
simple purescript that dont werk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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