mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-09 03:02:50 -06:00
Make Ident abstract; imports of Data.ByteString.Char8 down from 29 to 16 modules
Most of the explicit uses of ByteStrings were eliminated by using identS, identS = identC . BS.pack which was found in GF.Grammar.CF and moved to GF.Infra.Ident. The function prefixIdent :: String -> Ident -> Ident allowed one additional import of ByteString to be eliminated. The functions isArgIdent :: Ident -> Bool getArgIndex :: Ident -> Maybe Int were needed to eliminate explicit pattern matching on Ident from two modules.
This commit is contained in:
@@ -16,14 +16,13 @@ module GF.Compile.Compute.AppPredefined (
|
||||
isInPredefined, typPredefined, arrityPredefined, predefModInfo, appPredefined
|
||||
) where
|
||||
|
||||
import GF.Infra.Ident
|
||||
import GF.Infra.Ident(identS)
|
||||
import GF.Infra.Option
|
||||
import GF.Data.Operations
|
||||
import GF.Grammar
|
||||
import GF.Grammar.Predef
|
||||
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.ByteString.Char8 as BS
|
||||
import Text.PrettyPrint
|
||||
import Data.Char (isUpper,toUpper,toLower)
|
||||
|
||||
@@ -90,11 +89,8 @@ primitives = Map.fromList
|
||||
fun from to = oper (mkFunType from to)
|
||||
oper ty = ResOper (Just (noLoc ty)) Nothing
|
||||
|
||||
varL :: Ident
|
||||
varL = identC (BS.pack "L")
|
||||
|
||||
varP :: Ident
|
||||
varP = identC (BS.pack "P")
|
||||
varL = identS "L"
|
||||
varP = identS "P"
|
||||
|
||||
appPredefined :: Term -> Err (Term,Bool)
|
||||
appPredefined t = case t of
|
||||
@@ -127,7 +123,7 @@ appPredefined t = case t of
|
||||
(EInt i, EInt j) | f == cLessInt -> retb $ if i<j then predefTrue else predefFalse
|
||||
(EInt i, EInt j) | f == cPlus -> retb $ EInt $ i+j
|
||||
(_, t) | f == cShow && notVar t -> retb $ foldrC $ map K $ words $ render (ppTerm Unqualified 0 t)
|
||||
(_, K s) | f == cRead -> retb $ Cn (identC (BS.pack s)) --- because of K, only works for atomic tags
|
||||
(_, K s) | f == cRead -> retb $ Cn (identS s) --- because of K, only works for atomic tags
|
||||
(_, t) | f == cToStr -> trm2str t >>= retb
|
||||
_ -> retb t ---- prtBad "cannot compute predefined" t
|
||||
|
||||
|
||||
@@ -508,8 +508,7 @@ computeTermOpt gr = comput True where
|
||||
-- | argument variables cannot be glued
|
||||
checkNoArgVars :: Term -> Comp Term
|
||||
checkNoArgVars t = case t of
|
||||
Vr (IA _ _) -> fail $ glueErrorMsg $ ppTerm Unqualified 0 t
|
||||
Vr (IAV _ _ _) -> fail $ glueErrorMsg $ ppTerm Unqualified 0 t
|
||||
Vr x | isArgIdent x -> fail $ glueErrorMsg $ ppTerm Unqualified 0 t
|
||||
_ -> composOp checkNoArgVars t
|
||||
|
||||
glueErrorMsg s =
|
||||
|
||||
@@ -19,7 +19,6 @@ import Control.Monad(ap,liftM,liftM2,mplus,unless)
|
||||
import Data.List (findIndex,intersect,isInfixOf,nub,elemIndex,(\\))
|
||||
import Data.Char (isUpper,toUpper,toLower)
|
||||
import Text.PrettyPrint
|
||||
import qualified Data.ByteString.Char8 as BS
|
||||
import qualified Data.Map as Map
|
||||
--import Debug.Trace(trace)
|
||||
|
||||
@@ -80,7 +79,7 @@ resource env (m,c) =
|
||||
resourceValues :: SourceGrammar -> GlobalEnv
|
||||
resourceValues gr = env
|
||||
where
|
||||
env = GE gr rvs (L NoLoc IW)
|
||||
env = GE gr rvs (L NoLoc identW)
|
||||
rvs = Map.mapWithKey moduleResources (moduleMap gr)
|
||||
moduleResources m = Map.mapWithKey (moduleResource m) . jments
|
||||
moduleResource m c _info = do L l t <- lookupResDefLoc gr (m,c)
|
||||
@@ -115,7 +114,7 @@ value env t0 =
|
||||
Vr x -> var env x
|
||||
Q x@(m,f)
|
||||
| m == cPredef -> if f==cErrorType -- to be removed
|
||||
then let p = identC (BS.pack "P")
|
||||
then let p = identS "P"
|
||||
in const # value0 env (mkProd [(Implicit,p,typeType)] (Vr p) [])
|
||||
else const . flip VApp [] # predef f
|
||||
| otherwise -> const # resource env x --valueResDef (fst env) x
|
||||
|
||||
@@ -9,7 +9,6 @@ import GF.Grammar.Predef
|
||||
import GF.Data.Operations
|
||||
import Data.List (intersect)
|
||||
import Text.PrettyPrint
|
||||
import qualified Data.ByteString.Char8 as BS
|
||||
|
||||
normalForm :: SourceGrammar -> Term -> Term
|
||||
normalForm gr t = value2term gr [] (eval gr [] t)
|
||||
@@ -44,7 +43,7 @@ eval gr env (Vr x) = case lookup x env of
|
||||
Nothing -> error ("Unknown variable "++showIdent x)
|
||||
eval gr env (Q x)
|
||||
| x == (cPredef,cErrorType) -- to be removed
|
||||
= let varP = identC (BS.pack "P")
|
||||
= let varP = identS "P"
|
||||
in eval gr [] (mkProd [(Implicit,varP,typeType)] (Vr varP) [])
|
||||
| fst x == cPredef = VApp x []
|
||||
| otherwise = case lookupResDef gr x of
|
||||
|
||||
Reference in New Issue
Block a user