summaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2010-04-30 20:18:26 +0000
committerkrasimir <krasimir@chalmers.se>2010-04-30 20:18:26 +0000
commit9e7b914c3c5384feed3981acae89afaa7402e92b (patch)
tree1b1e1e1132cbfb752b38d2b9675583c7c7067092 /src/runtime
parent1c590e41f4a1e94e050980a6b161e4385a9e7cfa (diff)
for backward compatibility we have the old parse function again. the old functionality is exposed by parse_
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/haskell/PGF.hs30
1 files changed, 19 insertions, 11 deletions
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