"fix stuff lol"
This commit is contained in:
+33
-9
@@ -56,7 +56,7 @@ import Data.List (List, groupBy)
|
||||
import Data.Text.Encoding
|
||||
import Data.Either (either)
|
||||
import GHC.Generics (Generic)
|
||||
import Control.Lens
|
||||
import Control.Lens hiding (para)
|
||||
import Data.Generics.Labels
|
||||
import System.Process
|
||||
import GHC.IO.Unsafe (unsafePerformIO)
|
||||
@@ -71,9 +71,9 @@ import Language.Haskell.TH (Quote, location, Loc (..), ExpQ, varE, mkName, listE
|
||||
import qualified Data.Text as T
|
||||
import qualified Control.Category
|
||||
import Data.Data (Data (..), Typeable, cast)
|
||||
import Language.Haskell.TH.Syntax (lift, Lift)
|
||||
import Language.Haskell.TH.Syntax (lift, Lift, liftData)
|
||||
import GHC.IsList (fromList)
|
||||
import Data.Functor.Foldable (cata)
|
||||
import Data.Functor.Foldable (cata, para, embed)
|
||||
import Data.Functor.Classes (Show1(..))
|
||||
import Data.Vector (Vector)
|
||||
import Numeric.Natural (Natural)
|
||||
@@ -81,6 +81,7 @@ import Data.Maybe (fromMaybe)
|
||||
import Control.Applicative (Alternative((<|>)))
|
||||
import Debug.Pretty.Simple
|
||||
import qualified Data.Vector as V
|
||||
import qualified Data.Vector.Strict
|
||||
|
||||
|
||||
sexp :: SexpIso a => Iso' a Text
|
||||
@@ -295,10 +296,12 @@ instance SexpIso Natural where
|
||||
| otherwise = Right $ fromIntegral n
|
||||
g n = fromIntegral n
|
||||
|
||||
|
||||
class SpliceSexp a where
|
||||
spliceSexp :: a -> List Sexp
|
||||
|
||||
instance SexpIso a => SpliceSexp (Data.Vector.Strict.Vector a) where
|
||||
spliceSexp = toSexps
|
||||
|
||||
instance SexpIso a => SpliceSexp (Vector a) where
|
||||
spliceSexp = toSexps
|
||||
|
||||
@@ -329,6 +332,30 @@ unquoteSplicing xs
|
||||
& listE
|
||||
unquoteSplicing _ = Nothing
|
||||
|
||||
unquoteSplicingRecursive :: List Sexp.Sexp -> ExpQ
|
||||
unquoteSplicingRecursive xs = [| mconcat $(spans) |]
|
||||
where
|
||||
spans = xs
|
||||
& groupBy \cases
|
||||
(UnquoteSplicing _) _ -> False
|
||||
_ (UnquoteSplicing _) -> False
|
||||
_ _ -> True
|
||||
& fmap \case
|
||||
-- [e@(Unquote _)] ->
|
||||
-- case unquote e of
|
||||
-- Just x -> [| [$(x)] |]
|
||||
-- Nothing -> error "unreachable"
|
||||
[UnquoteSplicing x] ->
|
||||
[| spliceSexp $(varE (mkName (T.unpack x))) |]
|
||||
es -> listE $ unquoteRecursive <$> es
|
||||
& listE
|
||||
|
||||
unquoteRecursive :: Sexp.Sexp -> ExpQ
|
||||
unquoteRecursive = \case
|
||||
Unquote x -> [| stripLocation (toSexp $(varE (mkName (T.unpack x)))) |]
|
||||
SL.ParenList xs -> [|SL.ParenList $(unquoteSplicingRecursive xs)|]
|
||||
e -> liftData e
|
||||
|
||||
unquote :: Sexp.Sexp -> Maybe ExpQ
|
||||
unquote (Unquote x) =
|
||||
Just [| stripLocation . toSexp $ $(varE (mkName (T.unpack x))) |]
|
||||
@@ -340,13 +367,10 @@ _ParenList = prism' SL.ParenList \case
|
||||
_ -> Nothing
|
||||
|
||||
metaSexps :: List Sexp.Sexp -> Maybe ExpQ
|
||||
metaSexps = unquoteSplicing
|
||||
|
||||
metaSexpsV :: Vector Sexp.Sexp -> Maybe ExpQ
|
||||
metaSexpsV = unquoteSplicing . V.toList
|
||||
metaSexps = Just . unquoteSplicingRecursive
|
||||
|
||||
metaSexp :: Sexp.Sexp -> Maybe ExpQ
|
||||
metaSexp x = unquote x
|
||||
metaSexp = Just . unquoteRecursive
|
||||
|
||||
-- 뻘짓뻘짓뻘짓뻘짓뻘짓
|
||||
class Lift1 f where
|
||||
|
||||
Reference in New Issue
Block a user