1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 17:04:47 +03:00
semantic/app/Split.hs

34 lines
1.0 KiB
Haskell
Raw Normal View History

2015-12-01 22:18:13 +03:00
module Split where
2015-12-01 19:33:16 +03:00
import Diff
2015-12-01 22:18:13 +03:00
import Patch
import Syntax
import Term
import Unified
2015-12-01 22:35:23 +03:00
import Control.Comonad.Cofree
2015-12-01 23:31:02 +03:00
import qualified Data.Map as Map
2015-12-01 19:33:16 +03:00
import Rainbow
2015-12-01 22:35:23 +03:00
type ClassName = String
type Element a = Cofree (Syntax a) (Maybe ClassName, String)
2015-12-01 22:18:13 +03:00
2015-12-01 23:31:02 +03:00
data HTML =
Text String
| Span ClassName String
| Ul ClassName [HTML]
| Dl ClassName (Map.Map String HTML)
deriving (Eq, Show)
2015-12-01 19:33:16 +03:00
split :: Diff a Info -> String -> String -> IO ByteString
2015-12-01 22:18:13 +03:00
split _ _ _ = return mempty
splitDiff :: Diff a Info -> String -> String -> [(String, String)]
splitDiff _ _ _ = []
splitPatch :: String -> String -> Patch (Term a Info) -> (Maybe (Element a), Maybe (Element a))
splitPatch before after patch = (fmap (splitTerm before) $ Patch.before patch, fmap (splitTerm after) $ Patch.after patch)
2015-12-01 22:18:13 +03:00
2015-12-01 22:35:33 +03:00
splitTerm :: String -> Term a Info -> Element a
splitTerm source term = toElement term where
2015-12-01 23:30:54 +03:00
toElement ((Info range lineRange categories) :< syntax) = (foldr (const . Just) Nothing categories, substring range source) :< fmap toElement syntax