mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
use ByteString internally in Ident, CId and Label
This commit is contained in:
@@ -10,7 +10,7 @@ import GF.Devel.UseIO
|
||||
|
||||
-- | Compiles a number of source files and builds a 'GFCC' structure for them.
|
||||
compileToGFCC :: Options -> [FilePath] -> IOE GFCC
|
||||
compileToGFCC opts fs =
|
||||
compileToGFCC opts fs =
|
||||
do gr <- batchCompile opts fs
|
||||
let name = justModuleName (last fs)
|
||||
gc1 <- putPointE opts "linking ... " $
|
||||
|
||||
@@ -24,6 +24,7 @@ import GF.Grammar.PrGrammar (prt)
|
||||
import GF.Data.Operations
|
||||
import Data.List
|
||||
import qualified GF.Infra.Modules as M
|
||||
import qualified Data.ByteString.Char8 as BS
|
||||
|
||||
type OptSpec = [Integer] ---
|
||||
|
||||
@@ -110,7 +111,7 @@ factor c i t = case t of
|
||||
|
||||
--- we hope this will be fresh and don't check... in GFC would be safe
|
||||
|
||||
qqIdent c i = identC ("q_" ++ prt c ++ "__" ++ show i)
|
||||
qqIdent c i = identC (BS.pack ("q_" ++ prt c ++ "__" ++ show i))
|
||||
|
||||
|
||||
-- we need to replace subterms
|
||||
|
||||
@@ -42,7 +42,7 @@ mkRules conf f t = (fun f ty, lin f (takeWhile (/=':') t)) where
|
||||
args = mkArgs conf ts
|
||||
ty = concat [a ++ " -> " | a <- map snd args] ++ val
|
||||
(ts,val) = let tt = lexTerm t in (init tt,last tt)
|
||||
--- f = mkIdent t
|
||||
--- f = identV t
|
||||
fun c a = unwords [" fun", c, ":",a,";"]
|
||||
lin c a = unwords $ [" lin", c] ++ map fst args ++ ["=",a,";"]
|
||||
|
||||
|
||||
@@ -130,9 +130,9 @@ evalCncInfo opts gr cnc abs (c,info) = do
|
||||
CncCat ptyp pde ppr -> do
|
||||
pde' <- case (ptyp,pde) of
|
||||
(Yes typ, Yes de) ->
|
||||
liftM yes $ pEval ([(strVar, typeStr)], typ) de
|
||||
liftM yes $ pEval ([(varStr, typeStr)], typ) de
|
||||
(Yes typ, Nope) ->
|
||||
liftM yes $ mkLinDefault gr typ >>= partEval noOptions gr ([(strVar, typeStr)],typ)
|
||||
liftM yes $ mkLinDefault gr typ >>= partEval noOptions gr ([(varStr, typeStr)],typ)
|
||||
(May b, Nope) ->
|
||||
return $ May b
|
||||
_ -> return pde -- indirection
|
||||
@@ -248,7 +248,7 @@ recordExpand typ trm = case unComputed typ of
|
||||
mkLinDefault :: SourceGrammar -> Type -> Err Term
|
||||
mkLinDefault gr typ = do
|
||||
case unComputed typ of
|
||||
RecType lts -> mapPairsM mkDefField lts >>= (return . Abs strVar . R . mkAssign)
|
||||
RecType lts -> mapPairsM mkDefField lts >>= (return . Abs varStr . R . mkAssign)
|
||||
_ -> prtBad "linearization type must be a record type, not" typ
|
||||
where
|
||||
mkDefField typ = case unComputed typ of
|
||||
@@ -256,7 +256,7 @@ mkLinDefault gr typ = do
|
||||
t' <- mkDefField t
|
||||
let T _ cs = mkWildCases t'
|
||||
return $ T (TWild p) cs
|
||||
Sort "Str" -> return $ Vr strVar
|
||||
Sort "Str" -> return $ Vr varStr
|
||||
QC q p -> lookupFirstTag gr q p
|
||||
RecType r -> do
|
||||
let (ls,ts) = unzip r
|
||||
|
||||
@@ -23,6 +23,7 @@ import GF.Infra.Ident
|
||||
import GF.Infra.Modules
|
||||
import GF.Grammar.Macros
|
||||
import GF.Grammar.Lookup
|
||||
import GF.Grammar.Predef
|
||||
|
||||
import GF.Data.Operations
|
||||
|
||||
@@ -60,4 +61,4 @@ remlTerm gr trm = case trm of
|
||||
look c = err (const $ return defLinType) return $ lookupLincat gr m c
|
||||
m = case [cnc | (cnc,ModMod m) <- modules gr, isModCnc m] of
|
||||
cnc:_ -> cnc -- actually there is always exactly one
|
||||
_ -> zIdent "CNC"
|
||||
_ -> cCNC
|
||||
|
||||
@@ -29,6 +29,7 @@ module GF.Compile.Rename (renameGrammar,
|
||||
|
||||
import GF.Grammar.Grammar
|
||||
import GF.Grammar.Values
|
||||
import GF.Grammar.Predef
|
||||
import GF.Infra.Modules
|
||||
import GF.Infra.Ident
|
||||
import GF.Grammar.Macros
|
||||
@@ -90,11 +91,9 @@ renameIdentTerm env@(act,imps) t =
|
||||
[(m, st) | (OSimple _ m, st) <- imps] -- qualif is always possible
|
||||
|
||||
-- this facility is mainly for BWC with GF1: you need not import PredefAbs
|
||||
predefAbs c s = case c of
|
||||
IC "Int" -> return $ Q cPredefAbs cInt
|
||||
IC "Float" -> return $ Q cPredefAbs cFloat
|
||||
IC "String" -> return $ Q cPredefAbs cString
|
||||
_ -> Bad s
|
||||
predefAbs c s
|
||||
| isPredefCat c = return $ Q cPredefAbs c
|
||||
| otherwise = Bad s
|
||||
|
||||
ident alt c = case lookupTree prt c act of
|
||||
Ok f -> return $ f c
|
||||
@@ -104,7 +103,6 @@ renameIdentTerm env@(act,imps) t =
|
||||
fs -> case nub [f c | f <- fs] of
|
||||
[tr] -> return tr
|
||||
ts@(t:_) -> trace ("WARNING: conflict" +++ unwords (map prt ts)) (return t)
|
||||
---- ts -> return $ Strs $ (cnIC "#conflict") : reverse ts
|
||||
-- a warning will be generated in CheckGrammar, and the head returned
|
||||
-- in next V:
|
||||
-- Bad $ "conflicting imports:" +++ unwords (map prt ts)
|
||||
|
||||
Reference in New Issue
Block a user