diff options
| author | kr.angelov <kr.angelov@chalmers.se> | 2008-06-04 07:49:58 +0000 |
|---|---|---|
| committer | kr.angelov <kr.angelov@chalmers.se> | 2008-06-04 07:49:58 +0000 |
| commit | a3f4910bdb5d00d0cb460950690ffd90559a6a53 (patch) | |
| tree | 37d3e9a0a3f802e861f3e1c0baa6cacce59c84f9 /src-3.0/PGF.hs | |
| parent | 27dda59db4be007d4daa58f8f0a12873f26af1d4 (diff) | |
cleanup, document and export the completion API
Diffstat (limited to 'src-3.0/PGF.hs')
| -rw-r--r-- | src-3.0/PGF.hs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src-3.0/PGF.hs b/src-3.0/PGF.hs index 7a09bef59..49340e043 100644 --- a/src-3.0/PGF.hs +++ b/src-3.0/PGF.hs @@ -37,6 +37,10 @@ module PGF( -- ** Parsing parse, parseAllLang, parseAll, + + -- ** Word Completion (Incremental Parsing) + Incremental.ParseState, + initState, Incremental.nextState, Incremental.getCompletions, extractExps, -- ** Generation generateRandom, generateAll, generateAllDepth @@ -52,6 +56,7 @@ import PGF.Raw.Convert import PGF.Raw.Parse import PGF.Raw.Print (printTree) import PGF.Parsing.FCFG +import qualified PGF.Parsing.FCFG.Incremental as Incremental import GF.Text.UTF8 import GF.Data.ErrM @@ -119,6 +124,16 @@ parseAll :: PGF -> Category -> String -> [[Exp]] -- if the grammar is ambiguous. parseAllLang :: PGF -> Category -> String -> [(Language,[Exp])] +-- | Creates an initial parsing state for a given language and +-- startup category. +initState :: PGF -> Language -> Category -> Incremental.ParseState + +-- | This function extracts the list of all completed parse trees +-- that spans the whole input consumed so far. The trees are also +-- limited by the category specified, which is usually +-- the same as the startup category. +extractExps :: Incremental.ParseState -> Category -> [Exp] + -- | The same as 'generateAllDepth' but does not limit -- the depth in the generation. generateAll :: PGF -> Category -> [Exp] @@ -183,6 +198,16 @@ parseAll mgr cat = map snd . parseAllLang mgr cat parseAllLang mgr cat s = [(lang,ts) | lang <- languages mgr, let ts = parse mgr lang cat s, not (null ts)] +initState pgf lang cat = Incremental.initState pinfo catCId + where + langCId = mkCId lang + catCId = mkCId cat + pinfo = case lookParser pgf langCId of + Just pinfo -> pinfo + _ -> error ("Unknown language: " ++ lang) + +extractExps state cat = Incremental.extractExps state (mkCId cat) + generateRandom pgf cat = do gen <- newStdGen return $ genRandom gen pgf (mkCId cat) |
