forked from GitHub/gf-core
added timeout to gr -cf
This commit is contained in:
@@ -339,7 +339,10 @@ qualifTop :: StateGrammar -> G.QIdent -> G.QIdent
|
|||||||
qualifTop gr (_,c) = (absId gr,c)
|
qualifTop gr (_,c) = (absId gr,c)
|
||||||
|
|
||||||
stateGrammarOfLang :: ShellState -> Language -> StateGrammar
|
stateGrammarOfLang :: ShellState -> Language -> StateGrammar
|
||||||
stateGrammarOfLang st0 l = StGr {
|
stateGrammarOfLang = stateGrammarOfLangOpt True
|
||||||
|
|
||||||
|
stateGrammarOfLangOpt :: Bool -> ShellState -> Language -> StateGrammar
|
||||||
|
stateGrammarOfLangOpt purg st0 l = StGr {
|
||||||
absId = err (const (identC "Abs")) id $ M.abstractOfConcrete allCan l, ---
|
absId = err (const (identC "Abs")) id $ M.abstractOfConcrete allCan l, ---
|
||||||
cncId = l,
|
cncId = l,
|
||||||
grammar = allCan,
|
grammar = allCan,
|
||||||
@@ -352,7 +355,7 @@ stateGrammarOfLang st0 l = StGr {
|
|||||||
loptions = errVal noOptions $ lookupOptionsCan allCan
|
loptions = errVal noOptions $ lookupOptionsCan allCan
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
st = purgeShellState $ errVal st0 $ changeMain (Just l) st0
|
st = (if purg then purgeShellState else id) $ errVal st0 $ changeMain (Just l) st0
|
||||||
allCan = canModules st
|
allCan = canModules st
|
||||||
|
|
||||||
grammarOfLang :: ShellState -> Language -> CanonGrammar
|
grammarOfLang :: ShellState -> Language -> CanonGrammar
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ import Data.List
|
|||||||
import Control.Monad
|
import Control.Monad
|
||||||
import System.Random
|
import System.Random
|
||||||
|
|
||||||
|
-- | this parameter tells how many constructors at most are generated in a tree
|
||||||
|
timeout :: Int
|
||||||
|
timeout = 99
|
||||||
|
|
||||||
-- | generate an infinite list of trees, with their probabilities
|
-- | generate an infinite list of trees, with their probabilities
|
||||||
generateRandomTreesProb :: Options -> StdGen -> GFCGrammar -> Probs -> Cat -> [Exp]
|
generateRandomTreesProb :: Options -> StdGen -> GFCGrammar -> Probs -> Cat -> [Exp]
|
||||||
@@ -159,12 +162,15 @@ randomTrees :: StdGen -> SGrammar -> SCat -> [STree]
|
|||||||
randomTrees gen = genTrees (randomRs (0.0, 1.0) gen)
|
randomTrees gen = genTrees (randomRs (0.0, 1.0) gen)
|
||||||
|
|
||||||
genTrees :: [Double] -> SGrammar -> SCat -> [STree]
|
genTrees :: [Double] -> SGrammar -> SCat -> [STree]
|
||||||
genTrees ds gr cat =
|
genTrees ds0 gr cat =
|
||||||
let (t,k) = genTree ds gr cat
|
let (ds,ds2) = splitAt (timeout+1) ds0 -- for time out, else ds
|
||||||
in t : genTrees (drop k ds) gr cat
|
(t,k) = genTree ds gr cat
|
||||||
|
in (if k>timeout then id else (t:)) -- don't accept with metas
|
||||||
|
(genTrees ds2 gr cat) -- else (drop k ds)
|
||||||
|
|
||||||
genTree :: [Double] -> SGrammar -> SCat -> (STree,Int)
|
genTree :: [Double] -> SGrammar -> SCat -> (STree,Int)
|
||||||
genTree rs gr = gett rs where
|
genTree rs gr = gett rs where
|
||||||
|
gett [] cat = (SMeta cat,1) -- time-out case
|
||||||
gett ds "String" = (SString "foo",1)
|
gett ds "String" = (SString "foo",1)
|
||||||
gett ds "Int" = (SInt 1978,1)
|
gett ds "Int" = (SInt 1978,1)
|
||||||
gett ds "Float" = (SFloat 3.1415926, 1)
|
gett ds "Float" = (SFloat 3.1415926, 1)
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ linearize mgr lang =
|
|||||||
untok .
|
untok .
|
||||||
linTree2string noMark (canModules mgr) (zIdent lang)
|
linTree2string noMark (canModules mgr) (zIdent lang)
|
||||||
where
|
where
|
||||||
sgr = stateGrammarOfLang mgr (zIdent lang)
|
sgr = stateGrammarOfLangOpt False mgr (zIdent lang)
|
||||||
untok = customOrDefault noOptions useUntokenizer customUntokenizer sgr
|
untok = customOrDefault noOptions useUntokenizer customUntokenizer sgr
|
||||||
|
|
||||||
showTree t = prt_ $ tree2exp t
|
showTree t = prt_ $ tree2exp t
|
||||||
|
|||||||
Reference in New Issue
Block a user