1
0
forked from GitHub/gf-core

polish the PGF API and make Expr and Type abstract types. Tree is a type synonym of Expr

This commit is contained in:
krasimir
2009-09-11 13:45:34 +00:00
parent 28a7c4b5c7
commit 1cdf171251
31 changed files with 205 additions and 159 deletions

View File

@@ -4,7 +4,7 @@ module PGF.Parsing.FCFG.Incremental
, initState
, nextState
, getCompletions
, extractExps
, extractTrees
, parse
) where
@@ -21,12 +21,13 @@ import Control.Monad
import GF.Data.SortedList
import PGF.CId
import PGF.Data
import PGF.Expr(Tree)
import PGF.Macros
import PGF.TypeCheck
import Debug.Trace
parse :: PGF -> Language -> Type -> [String] -> [Expr]
parse pgf lang typ toks = maybe [] (\ps -> extractExps ps typ) (foldM nextState (initState pgf lang typ) toks)
parse pgf lang typ toks = maybe [] (\ps -> extractTrees ps typ) (foldM nextState (initState pgf lang typ) toks)
-- | Creates an initial parsing state for a given language and
-- startup category.
@@ -43,7 +44,7 @@ initState pgf lang (DTyp _ start _) =
pinfo =
case lookParser pgf lang of
Just pinfo -> pinfo
_ -> error ("Unknown language: " ++ prCId lang)
_ -> error ("Unknown language: " ++ showCId lang)
in State pgf
pinfo
@@ -97,8 +98,8 @@ getCompletions (State pgf pinfo chart items) w =
-- 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 :: ParseState -> Type -> [Expr]
extractExps (State pgf pinfo chart items) ty@(DTyp _ start _) =
extractTrees :: ParseState -> Type -> [Tree]
extractTrees (State pgf pinfo chart items) ty@(DTyp _ start _) =
nubsort [e1 | e <- exps, Right e1 <- [checkExpr pgf e ty]]
where
(mb_agenda,acc) = TMap.decompose items