mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-26 11:18:55 -06:00
prelude sources to lib/src; present in StructuralEng; refactored checkGFCC
This commit is contained in:
@@ -40,7 +40,8 @@ pretest:
|
|||||||
echo "gr -cat=Cl -number=11 -prob | tb" | $(GF) -probs=lang.gfprob -path=present:prelude -nocf ../present/Lang???.gfc
|
echo "gr -cat=Cl -number=11 -prob | tb" | $(GF) -probs=lang.gfprob -path=present:prelude -nocf ../present/Lang???.gfc
|
||||||
|
|
||||||
prelude:
|
prelude:
|
||||||
$(GFC) ../prelude/*.gf
|
$(GFC) ../src/*.gf
|
||||||
|
cp -p ../src/*.gf? ../prelude
|
||||||
|
|
||||||
alltenses:
|
alltenses:
|
||||||
# $(GFC) arabic/GrammarAra.gf
|
# $(GFC) arabic/GrammarAra.gf
|
||||||
@@ -153,7 +154,11 @@ gfdoc:
|
|||||||
mv ../prelude/*.html doc/gfdoc
|
mv ../prelude/*.html doc/gfdoc
|
||||||
|
|
||||||
gf3:
|
gf3:
|
||||||
export GF_LIB_PATH=..; $(MAKE) -e gf3present gf3alltenses
|
export GF_LIB_PATH=..; $(MAKE) -e gf3prelude gf3present gf3alltenses
|
||||||
|
|
||||||
|
gf3prelude:
|
||||||
|
$(GFNew) ../src/*.gf
|
||||||
|
cp -p ../src/*.gfo ../prelude
|
||||||
|
|
||||||
gf3alltenses:
|
gf3alltenses:
|
||||||
# $(GFNew) arabic/GrammarAra.gf
|
# $(GFNew) arabic/GrammarAra.gf
|
||||||
|
|||||||
@@ -20,8 +20,15 @@ concrete StructuralEng of Structural = CatEng **
|
|||||||
by8agent_Prep = ss "by" ;
|
by8agent_Prep = ss "by" ;
|
||||||
by8means_Prep = ss "by" ;
|
by8means_Prep = ss "by" ;
|
||||||
can8know_VV, can_VV = {
|
can8know_VV, can_VV = {
|
||||||
s = table VVForm [["be able to"] ; "can" ; ["been able to"] ;
|
s = table {
|
||||||
["being able to"] ; "could" ; "can't" ; "couldn't"] ;
|
VVF VInf => ["be able to"] ;
|
||||||
|
VVF VPres => "can" ;
|
||||||
|
VVF VPPart => ["been able to"] ;
|
||||||
|
VVF VPresPart => ["being able to"] ;
|
||||||
|
VVF VPast => "could" ; --# notpresent
|
||||||
|
VVPastNeg => "couldn't" ; --# notpresent
|
||||||
|
VVPresNeg => "can't"
|
||||||
|
} ;
|
||||||
isAux = True
|
isAux = True
|
||||||
} ;
|
} ;
|
||||||
during_Prep = ss "during" ;
|
during_Prep = ss "during" ;
|
||||||
@@ -51,8 +58,15 @@ concrete StructuralEng of Structural = CatEng **
|
|||||||
most_Predet = ss "most" ;
|
most_Predet = ss "most" ;
|
||||||
much_Det = mkDeterminer Sg "much" ;
|
much_Det = mkDeterminer Sg "much" ;
|
||||||
must_VV = {
|
must_VV = {
|
||||||
s = table VVForm [["have to"] ; "must" ; ["had to"] ;
|
s = table {
|
||||||
["having to"] ; ["had to"] ; "mustn't" ; ["hadn't to"]] ; ----
|
VVF VInf => ["have to"] ;
|
||||||
|
VVF VPres => "must" ;
|
||||||
|
VVF VPPart => ["had to"] ;
|
||||||
|
VVF VPresPart => ["having to"] ;
|
||||||
|
VVF VPast => ["had to"] ; --# notpresent
|
||||||
|
VVPastNeg => ["hadn't to"] ; --# notpresent
|
||||||
|
VVPresNeg => "mustn't"
|
||||||
|
} ;
|
||||||
isAux = True
|
isAux = True
|
||||||
} ;
|
} ;
|
||||||
no_Phr = ss "no" ;
|
no_Phr = ss "no" ;
|
||||||
|
|||||||
@@ -22,9 +22,7 @@ importGrammar mgr0 opts files = do
|
|||||||
gr <- batchCompile opts files
|
gr <- batchCompile opts files
|
||||||
let name = justModuleName (last files)
|
let name = justModuleName (last files)
|
||||||
let (abs,gfcc0) = mkCanon2gfcc opts name gr
|
let (abs,gfcc0) = mkCanon2gfcc opts name gr
|
||||||
(gfcc1,b) <- checkGFCC gfcc0
|
gfcc1 <- checkGFCCio gfcc0
|
||||||
if b then return () else do
|
|
||||||
putStrLn "Corrupted GFCC"
|
|
||||||
return $ if oElem (iOpt "noopt") opts then gfcc1 else optGFCC gfcc1
|
return $ if oElem (iOpt "noopt") opts then gfcc1 else optGFCC gfcc1
|
||||||
"gfcc" ->
|
"gfcc" ->
|
||||||
mapM file2gfcc files >>= return . foldl1 unionGFCC
|
mapM file2gfcc files >>= return . foldl1 unionGFCC
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import GF.GFCC.DataGFCC
|
|||||||
import GF.GFCC.ParGFCC
|
import GF.GFCC.ParGFCC
|
||||||
import GF.Devel.UseIO
|
import GF.Devel.UseIO
|
||||||
import GF.Infra.Option
|
import GF.Infra.Option
|
||||||
|
import GF.GFCC.ErrM
|
||||||
|
|
||||||
mainGFC :: [String] -> IO ()
|
mainGFC :: [String] -> IO ()
|
||||||
mainGFC xx = do
|
mainGFC xx = do
|
||||||
@@ -20,32 +21,38 @@ mainGFC xx = do
|
|||||||
gr <- batchCompile opts fs
|
gr <- batchCompile opts fs
|
||||||
let name = justModuleName (last fs)
|
let name = justModuleName (last fs)
|
||||||
let (abs,gc0) = mkCanon2gfcc opts name gr
|
let (abs,gc0) = mkCanon2gfcc opts name gr
|
||||||
gc1 <- check gc0
|
gc1 <- checkGFCCio gc0
|
||||||
let gc = if oElem (iOpt "noopt") opts then gc1 else optGFCC gc1
|
let gc = if oElem (iOpt "noopt") opts then gc1 else optGFCC gc1
|
||||||
let target = abs ++ ".gfcc"
|
let target = targetName opts abs
|
||||||
writeFile target (printGFCC gc)
|
let gfccFile = target ++ ".gfcc"
|
||||||
putStrLn $ "wrote file " ++ target
|
writeFile gfccFile (printGFCC gc)
|
||||||
mapM_ (alsoPrint opts abs gc) printOptions
|
putStrLn $ "wrote file " ++ gfccFile
|
||||||
|
mapM_ (alsoPrint opts target gc) printOptions
|
||||||
|
|
||||||
-- gfc -o target.gfcc source_1.gfcc ... source_n.gfcc
|
-- gfc -o target.gfcc source_1.gfcc ... source_n.gfcc
|
||||||
_ | all ((=="gfcc") . fileSuffix) fs && oElem (iOpt "o") opts -> do
|
_ | all ((=="gfcc") . fileSuffix) fs -> do
|
||||||
let target:sources = fs
|
gfccs <- mapM file2gfcc fs
|
||||||
gfccs <- mapM file2gfcc sources
|
|
||||||
let gfcc = foldl1 unionGFCC gfccs
|
let gfcc = foldl1 unionGFCC gfccs
|
||||||
writeFile target (printGFCC gfcc)
|
let abs = printCId $ absname gfcc
|
||||||
|
let target = targetName opts abs
|
||||||
|
let gfccFile = target ++ ".gfcc"
|
||||||
|
writeFile gfccFile (printGFCC gfcc)
|
||||||
|
putStrLn $ "wrote file " ++ gfccFile
|
||||||
|
mapM_ (alsoPrint opts target gfcc) printOptions
|
||||||
|
|
||||||
_ -> do
|
_ -> do
|
||||||
mapM_ (batchCompile opts) (map return fs)
|
mapM_ (batchCompile opts) (map return fs)
|
||||||
putStrLn "Done."
|
putStrLn "Done."
|
||||||
|
|
||||||
check gfcc = do
|
file2gfcc f = do
|
||||||
(gc,b) <- checkGFCC gfcc
|
f <- readFileIf f
|
||||||
putStrLn $ if b then "OK" else "Corrupted GFCC"
|
case pGrammar (myLexer f) of
|
||||||
return gc
|
Ok g -> return (mkGFCC g)
|
||||||
|
Bad s -> error s
|
||||||
file2gfcc f =
|
|
||||||
readFileIf f >>= err (error) (return . mkGFCC) . pGrammar . myLexer
|
|
||||||
|
|
||||||
|
targetName opts abs = case getOptVal opts (aOpt "target") of
|
||||||
|
Just n -> n
|
||||||
|
_ -> abs
|
||||||
|
|
||||||
---- TODO: nicer and richer print options
|
---- TODO: nicer and richer print options
|
||||||
|
|
||||||
@@ -66,4 +73,4 @@ printOptions = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
usageMsg =
|
usageMsg =
|
||||||
"usage: gfc (-h | --make (-noopt) (-js | -jsref | -haskell | -haskell_gadt)) (-src) FILES"
|
"usage: gfc (-h | --make (-noopt) (-target=PREFIX) (-js | -jsref | -haskell | -haskell_gadt)) (-src) FILES"
|
||||||
|
|||||||
@@ -380,7 +380,6 @@ term2term cgr env@(labels,untyps,typs) tr = case tr of
|
|||||||
P t l -> r2r tr
|
P t l -> r2r tr
|
||||||
PI t l i -> EInt $ toInteger i
|
PI t l i -> EInt $ toInteger i
|
||||||
|
|
||||||
T _ [_] -> error $ "single" +++ prt tr
|
|
||||||
T (TWild _) _ -> error $ "wild" +++ prt tr
|
T (TWild _) _ -> error $ "wild" +++ prt tr
|
||||||
T (TComp ty) cs -> t2t $ V ty $ map snd cs ---- should be elim'ed in tc
|
T (TComp ty) cs -> t2t $ V ty $ map snd cs ---- should be elim'ed in tc
|
||||||
T (TTyped ty) cs -> t2t $ V ty $ map snd cs ---- should be elim'ed in tc
|
T (TTyped ty) cs -> t2t $ V ty $ map snd cs ---- should be elim'ed in tc
|
||||||
|
|||||||
@@ -13,3 +13,4 @@ prGFCC printer gr = case printer of
|
|||||||
"js" -> gfcc2js gr
|
"js" -> gfcc2js gr
|
||||||
"jsref" -> gfcc2grammarRef gr
|
"jsref" -> gfcc2grammarRef gr
|
||||||
_ -> printGFCC gr
|
_ -> printGFCC gr
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module GF.GFCC.CheckGFCC where
|
module GF.GFCC.CheckGFCC (checkGFCC, checkGFCCio) where
|
||||||
|
|
||||||
import GF.GFCC.Macros
|
import GF.GFCC.Macros
|
||||||
import GF.GFCC.DataGFCC
|
import GF.GFCC.DataGFCC
|
||||||
@@ -7,32 +7,47 @@ import GF.GFCC.ErrM
|
|||||||
|
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
import Debug.Trace
|
||||||
|
|
||||||
andMapM :: Monad m => (a -> m Bool) -> [a] -> m Bool
|
checkGFCCio :: GFCC -> IO GFCC
|
||||||
andMapM f xs = mapM f xs >>= return . and
|
checkGFCCio gfcc = case checkGFCC gfcc of
|
||||||
|
Ok (gc,b) -> do
|
||||||
|
putStrLn $ if b then "OK" else "Corrupted GFCC"
|
||||||
|
return gc
|
||||||
|
Bad s -> do
|
||||||
|
putStrLn s
|
||||||
|
error "building GFCC failed"
|
||||||
|
|
||||||
labelBoolIO :: String -> IO (x,Bool) -> IO (x,Bool)
|
checkGFCC :: GFCC -> Err (GFCC,Bool)
|
||||||
labelBoolIO msg iob = do
|
|
||||||
(x,b) <- iob
|
|
||||||
if b then return (x,b) else (putStrLn msg >> return (x,b))
|
|
||||||
|
|
||||||
checkGFCC :: GFCC -> IO (GFCC,Bool)
|
|
||||||
checkGFCC gfcc = do
|
checkGFCC gfcc = do
|
||||||
(cs,bs) <- mapM (checkConcrete gfcc)
|
(cs,bs) <- mapM (checkConcrete gfcc)
|
||||||
(Map.assocs (concretes gfcc)) >>= return . unzip
|
(Map.assocs (concretes gfcc)) >>= return . unzip
|
||||||
return (gfcc {concretes = Map.fromAscList cs}, and bs)
|
return (gfcc {concretes = Map.fromAscList cs}, and bs)
|
||||||
|
|
||||||
checkConcrete :: GFCC -> (CId,Concr) -> IO ((CId,Concr),Bool)
|
|
||||||
|
-- errors are non-fatal; replace with 'fail' to change this
|
||||||
|
msg s = trace s (return ())
|
||||||
|
|
||||||
|
andMapM :: Monad m => (a -> m Bool) -> [a] -> m Bool
|
||||||
|
andMapM f xs = mapM f xs >>= return . and
|
||||||
|
|
||||||
|
labelBoolErr :: String -> Err (x,Bool) -> Err (x,Bool)
|
||||||
|
labelBoolErr ms iob = do
|
||||||
|
(x,b) <- iob
|
||||||
|
if b then return (x,b) else (msg ms >> return (x,b))
|
||||||
|
|
||||||
|
|
||||||
|
checkConcrete :: GFCC -> (CId,Concr) -> Err ((CId,Concr),Bool)
|
||||||
checkConcrete gfcc (lang,cnc) =
|
checkConcrete gfcc (lang,cnc) =
|
||||||
labelBoolIO ("happened in language " ++ prt lang) $ do
|
labelBoolErr ("happened in language " ++ prt lang) $ do
|
||||||
(rs,bs) <- mapM checkl (Map.assocs (lins cnc)) >>= return . unzip
|
(rs,bs) <- mapM checkl (Map.assocs (lins cnc)) >>= return . unzip
|
||||||
return ((lang,cnc{lins = Map.fromAscList rs}),and bs)
|
return ((lang,cnc{lins = Map.fromAscList rs}),and bs)
|
||||||
where
|
where
|
||||||
checkl = checkLin gfcc lang
|
checkl = checkLin gfcc lang
|
||||||
|
|
||||||
checkLin :: GFCC -> CId -> (CId,Term) -> IO ((CId,Term),Bool)
|
checkLin :: GFCC -> CId -> (CId,Term) -> Err ((CId,Term),Bool)
|
||||||
checkLin gfcc lang (f,t) =
|
checkLin gfcc lang (f,t) =
|
||||||
labelBoolIO ("happened in function " ++ prt f) $ do
|
labelBoolErr ("happened in function " ++ prt f) $ do
|
||||||
(t',b) <- checkTerm (lintype gfcc lang f) t --- $ inline gfcc lang t
|
(t',b) <- checkTerm (lintype gfcc lang f) t --- $ inline gfcc lang t
|
||||||
return ((f,t'),b)
|
return ((f,t'),b)
|
||||||
|
|
||||||
@@ -82,17 +97,17 @@ inferTerm args trm = case trm of
|
|||||||
returnt ty = return (trm,ty)
|
returnt ty = return (trm,ty)
|
||||||
infer = inferTerm args
|
infer = inferTerm args
|
||||||
|
|
||||||
checkTerm :: LinType -> Term -> IO (Term,Bool)
|
checkTerm :: LinType -> Term -> Err (Term,Bool)
|
||||||
checkTerm (args,val) trm = case inferTerm args trm of
|
checkTerm (args,val) trm = case inferTerm args trm of
|
||||||
Ok (t,ty) -> if eqType ty val
|
Ok (t,ty) -> if eqType ty val
|
||||||
then return (t,True)
|
then return (t,True)
|
||||||
else do
|
else do
|
||||||
putStrLn $ "term: " ++ prt trm ++
|
msg ("term: " ++ prt trm ++
|
||||||
"\nexpected type: " ++ prt val ++
|
"\nexpected type: " ++ prt val ++
|
||||||
"\ninferred type: " ++ prt ty
|
"\ninferred type: " ++ prt ty)
|
||||||
return (t,False)
|
return (t,False)
|
||||||
Bad s -> do
|
Bad s -> do
|
||||||
putStrLn s
|
msg s
|
||||||
return (trm,False)
|
return (trm,False)
|
||||||
|
|
||||||
eqType :: CType -> CType -> Bool
|
eqType :: CType -> CType -> Bool
|
||||||
|
|||||||
@@ -99,6 +99,8 @@ printGFCC gfcc0 = compactPrintGFCC $ printTree $ Grm
|
|||||||
[Lin f v | (f,v) <- assocs (paramlincats cnc)]
|
[Lin f v | (f,v) <- assocs (paramlincats cnc)]
|
||||||
gfcc = utf8GFCC gfcc0
|
gfcc = utf8GFCC gfcc0
|
||||||
|
|
||||||
|
printCId :: CId -> String
|
||||||
|
printCId = printTree
|
||||||
|
|
||||||
-- merge two GFCCs; fails is differens absnames; priority to second arg
|
-- merge two GFCCs; fails is differens absnames; priority to second arg
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user