summaryrefslogtreecommitdiff
path: root/src/GF
diff options
context:
space:
mode:
authoraarne <unknown>2004-04-30 11:28:35 +0000
committeraarne <unknown>2004-04-30 11:28:35 +0000
commitc9d10ab5ed8b82ba0f74a25ca30103ccf0985e6d (patch)
tree610a280c538abc742941b5d31b7d5912d0f7b0bd /src/GF
parent36a68bce6ab94a4824698b9c3d7b4d0da4898eea (diff)
random gen to fill given term
Diffstat (limited to 'src/GF')
-rw-r--r--src/GF/CF/CFIdent.hs4
-rw-r--r--src/GF/Shell.hs12
-rw-r--r--src/GF/Shell/PShell.hs2
-rw-r--r--src/GF/UseGrammar/Parsing.hs3
-rw-r--r--src/GF/UseGrammar/Tokenize.hs2
5 files changed, 14 insertions, 9 deletions
diff --git a/src/GF/CF/CFIdent.hs b/src/GF/CF/CFIdent.hs
index 95d532e2d..28903e5d7 100644
--- a/src/GF/CF/CFIdent.hs
+++ b/src/GF/CF/CFIdent.hs
@@ -43,7 +43,7 @@ prCFTok t = case t of
TL s -> s
TI i -> show i
TV x -> prt x
- TM i _ -> "?" ---
+ TM i m -> m --- "?" --- m
-- to build trees: the Atom contains a GF function, Cn | Meta | Vr | Literal
newtype CFFun = CFFun (Atom, Profile) deriving (Eq,Show)
@@ -157,6 +157,8 @@ str2cftoks = map tS . words . sstr
compatToks :: [CFTok] -> [CFTok] -> Bool
compatToks ts us = and [compatTok t u | (t,u) <- zip ts us]
+compatTok (TM _ _) _ = True --- hack because metas are renamed
+compatTok _ (TM _ _) = True
compatTok t u = any (`elem` (alts t)) (alts u) where
alts u = case u of
TC (c:s) -> [toLower c : s, toUpper c : s]
diff --git a/src/GF/Shell.hs b/src/GF/Shell.hs
index 9e922171f..2fdf6dabd 100644
--- a/src/GF/Shell.hs
+++ b/src/GF/Shell.hs
@@ -173,15 +173,17 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = case comm of
CTranslate il ol -> do
let a' = opST2CommandArg (optParseArgErr opts (sgr il)) a
returnArg (opTS2CommandArg (optLinearizeTreeVal opts (sgr ol)) a') sa
- CGenerateRandom n -> case a of
- ASTrm _ -> do
- case s2t a of
- ATrms [trm] -> do
+ CGenerateRandom n -> do
+ let
+ a' = case a of
+ ASTrm _ -> s2t a
+ _ -> a
+ case a' of
+ ATrms (trm:_) -> do
g <- newStdGen
case (goFirstMeta (tree2loc trm) >>= refineRandom g 41 cgr) of
Ok trm' -> returnArg (ATrms [loc2tree trm']) sa
Bad s -> returnArg (AError s) sa
- _ -> returnArg a sa
_ -> do
ts <- randomTreesIO opts gro (optIntOrN opts flagNumber n)
returnArg (ATrms ts) sa
diff --git a/src/GF/Shell/PShell.hs b/src/GF/Shell/PShell.hs
index 06554287b..9a1185032 100644
--- a/src/GF/Shell/PShell.hs
+++ b/src/GF/Shell/PShell.hs
@@ -71,7 +71,7 @@ pCommand ws = case ws of
"p" : s -> aString CParse s
"t" : i:o: s -> aString (CTranslate (language i) (language o)) s
"gr" : [] -> aUnit (CGenerateRandom 1)
- "gr" : t -> aTerm (CGenerateRandom 1) t
+ "gt" : t -> aTerm (CGenerateRandom 1) t
--- "gr" : n : [] -> aUnit (CGenerateRandom (readIntArg n)) -- deprecated 12/5/2001
"pt" : s -> aTerm CPutTerm s
----- "wt" : f : s -> aTerm (CWrapTerm (string2id f)) s
diff --git a/src/GF/UseGrammar/Parsing.hs b/src/GF/UseGrammar/Parsing.hs
index 48b6ffac6..5d601bc58 100644
--- a/src/GF/UseGrammar/Parsing.hs
+++ b/src/GF/UseGrammar/Parsing.hs
@@ -5,6 +5,7 @@ import qualified AbsGFC as C
import GFC
import MkGFC (trExp) ----
import CMacros
+import MMacros (refreshMetas)
import Linear
import Str
import CF
@@ -68,7 +69,7 @@ tokens2trms opts sg cn parser as = do
_ -> do
(ts1,ss) <- checkErr $ mapErr postParse ts0
if null ts1 then raise ss else return ()
- ts2 <- mapM (checkErr . (annotate gr) . trExp) ts1 ----
+ ts2 <- mapM (checkErr . annotate gr . refreshMetas [] . trExp) ts1 ----
if forgive then return ts2 else do
let tsss = [(t, allLinsOfTree gr cn t) | t <- ts2]
ps = [t | (t,ss) <- tsss,
diff --git a/src/GF/UseGrammar/Tokenize.hs b/src/GF/UseGrammar/Tokenize.hs
index b264075ba..22d70a9b1 100644
--- a/src/GF/UseGrammar/Tokenize.hs
+++ b/src/GF/UseGrammar/Tokenize.hs
@@ -29,7 +29,7 @@ mkCFTok s = case s of
mkCFTokVar :: String -> CFTok
mkCFTokVar s = case s of
- '?':_:_ -> tM s
+ '?':_:_ -> tM s --- "?" --- compat with prCF
'x':'_':_ -> tV s
'x':[] -> tV s
'$':xs@(_:_) -> if last s == '$' then tV (init xs) else tS s