From 9e7b914c3c5384feed3981acae89afaa7402e92b Mon Sep 17 00:00:00 2001 From: krasimir Date: Fri, 30 Apr 2010 20:18:26 +0000 Subject: for backward compatibility we have the old parse function again. the old functionality is exposed by parse_ --- src/runtime/haskell/PGF.hs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/runtime/haskell') diff --git a/src/runtime/haskell/PGF.hs b/src/runtime/haskell/PGF.hs index f2235cf37..26a727a47 100644 --- a/src/runtime/haskell/PGF.hs +++ b/src/runtime/haskell/PGF.hs @@ -58,7 +58,7 @@ module PGF( Forest.showBracketedString, -- ** Parsing - parse, parseWithRecovery, parseAllLang, parseAll, + parse, parseAllLang, parseAll, parse_, parseWithRecovery, -- ** Evaluation PGF.compute, paraphrase, @@ -139,10 +139,7 @@ readPGF :: FilePath -> IO PGF -- | Tries to parse the given string in the specified language -- and to produce abstract syntax expression. -parse :: PGF -> Language -> Type -> String -> (Parse.ParseResult,Maybe BracketedString) - --- | This is an experimental function. Use it on your own risk -parseWithRecovery :: PGF -> Language -> Type -> [Type] -> String -> (Parse.ParseResult,Maybe BracketedString) +parse :: PGF -> Language -> Type -> String -> [Tree] -- | The same as 'parseAllLang' but does not return -- the language. @@ -156,6 +153,12 @@ parseAll :: PGF -> Type -> String -> [[Tree]] -- for which at least one parsing is possible are listed. parseAllLang :: PGF -> Type -> String -> [(Language,[Tree])] +-- | The same as 'parse' but returns more detailed information +parse_ :: PGF -> Language -> Type -> String -> (Parse.ParseResult,Maybe BracketedString) + +-- | This is an experimental function. Use it on your own risk +parseWithRecovery :: PGF -> Language -> Type -> [Type] -> String -> (Parse.ParseResult,Maybe BracketedString) + -- | The same as 'generateAllDepth' but does not limit -- the depth in the generation, and doesn't give an initial expression. generateAll :: PGF -> Type -> [Expr] @@ -217,7 +220,17 @@ complete :: PGF -> Language -> Type -> String readPGF f = decodeFile f -parse pgf lang typ s = +parse pgf lang typ s = + case parse_ pgf lang typ s of + (Parse.ParseResult ts,_) -> ts + _ -> [] + +parseAll mgr typ = map snd . parseAllLang mgr typ + +parseAllLang mgr typ s = + [(lang,ts) | lang <- languages mgr, (Parse.ParseResult ts,_) <- [parse_ mgr lang typ s]] + +parse_ pgf lang typ s = case Map.lookup lang (concretes pgf) of Just cnc -> Parse.parse pgf lang typ (words s) Nothing -> error ("Unknown language: " ++ showCId lang) @@ -231,11 +244,6 @@ groupResults = Map.toList . foldr more Map.empty . start . concat more (l,s) = Map.insertWith (\ [x] xs -> if elem x xs then xs else (x : xs)) l s -parseAll mgr typ = map snd . parseAllLang mgr typ - -parseAllLang mgr typ s = - [(lang,ts) | lang <- languages mgr, (Parse.ParseResult ts,_) <- [parse mgr lang typ s], not (null ts)] - generateRandom pgf cat = do gen <- newStdGen return $ genRandom gen pgf cat -- cgit v1.2.3