{-# OPTIONS -fno-warn-orphans #-}
{-# LANGUAGE FlexibleInstances #-}
module Fay.Exts.NoAnnotation where
import Fay.Compiler.Prelude
import Data.List.Split (splitOn)
import Data.String
import qualified Language.Haskell.Exts as A
type Alt = A.Alt ()
type BangType = A.BangType ()
type ClassDecl = A.ClassDecl ()
type Decl = A.Decl ()
type DeclHead = A.DeclHead ()
type Ex = A.Exp ()
type Exp = A.Exp ()
type ExportSpec = A.ExportSpec ()
type FieldDecl = A.FieldDecl ()
type FieldUpdate = A.FieldUpdate ()
type GadtDecl = A.GadtDecl ()
type GuardedRhs = A.GuardedRhs ()
type ImportDecl = A.ImportDecl ()
type ImportSpec = A.ImportSpec ()
type Literal = A.Literal ()
type Match = A.Match ()
type Module = A.Module ()
type ModuleName = A.ModuleName ()
type ModulePragma = A.ModulePragma ()
type Name = A.Name ()
type Pat = A.Pat ()
type PatField = A.PatField ()
type QName = A.QName ()
type QOp = A.QOp ()
type QualConDecl = A.QualConDecl ()
type QualStmt = A.QualStmt ()
type Rhs = A.Rhs ()
type Sign = A.Sign ()
type SpecialCon = A.SpecialCon ()
type SrcLoc = A.SrcLoc
type SrcSpan = A.SrcSpan
type SrcSpanInfo = A.SrcSpanInfo
type Stmt = A.Stmt ()
type TyVarBind = A.TyVarBind ()
type Type = A.Type ()
unAnn :: Functor f => f a -> f ()
unAnn :: f a -> f ()
unAnn = f a -> f ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void
instance IsString (A.Name ()) where
fromString :: String -> Name ()
fromString n :: String
n@(Char
c:String
_)
| Char -> Bool
isAlpha Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' = () -> String -> Name ()
forall l. l -> String -> Name l
A.Ident () String
n
| Bool
otherwise = () -> String -> Name ()
forall l. l -> String -> Name l
A.Symbol () String
n
fromString [] = String -> Name ()
forall a. HasCallStack => String -> a
error String
"Name fromString: empty string"
instance IsString (A.QName ()) where
fromString :: String -> QName ()
fromString String
s = case String -> String -> [String]
forall a. Eq a => [a] -> [a] -> [[a]]
splitOn String
"." String
s of
[] -> String -> QName ()
forall a. HasCallStack => String -> a
error String
"QName fromString: empty string"
[String
x] -> () -> Name () -> QName ()
forall l. l -> Name l -> QName l
A.UnQual () (Name () -> QName ()) -> Name () -> QName ()
forall a b. (a -> b) -> a -> b
$ String -> Name ()
forall a. IsString a => String -> a
fromString String
x
[String]
xs -> () -> ModuleName () -> Name () -> QName ()
forall l. l -> ModuleName l -> Name l -> QName l
A.Qual () (String -> ModuleName ()
forall a. IsString a => String -> a
fromString (String -> ModuleName ()) -> String -> ModuleName ()
forall a b. (a -> b) -> a -> b
$ String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"." ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ [String] -> [String]
forall a. [a] -> [a]
init [String]
xs) (Name () -> QName ()) -> Name () -> QName ()
forall a b. (a -> b) -> a -> b
$ String -> Name ()
forall a. IsString a => String -> a
fromString ([String] -> String
forall a. [a] -> a
last [String]
xs)
instance IsString (A.ModuleName ()) where
fromString :: String -> ModuleName ()
fromString = () -> String -> ModuleName ()
forall l. l -> String -> ModuleName l
A.ModuleName ()