summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2009-08-19 20:59:43 +0000
committerkrasimir <krasimir@chalmers.se>2009-08-19 20:59:43 +0000
commit8da1aab8fff7adae50dfa7f5f13532a2980d375d (patch)
tree7aa223bb864d55d6eaae3ade3882128346150589 /src
parentf27c1785a779bf3fb2052c0efd70e4b319767a46 (diff)
add functions and functionType to the PGF API
Diffstat (limited to 'src')
-rw-r--r--src/PGF.hs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/PGF.hs b/src/PGF.hs
index fef4682da..4d059fd00 100644
--- a/src/PGF.hs
+++ b/src/PGF.hs
@@ -27,6 +27,9 @@ module PGF(
showType, readType,
categories, startCat,
+ -- * Functions
+ functions, functionType,
+
-- * Expressions
-- ** Identifiers
CId, mkCId, prCId, wildCId,
@@ -65,7 +68,7 @@ import PGF.Generate
import PGF.TypeCheck
import PGF.Paraphrase
import PGF.Macros
-import PGF.Data
+import PGF.Data hiding (functions)
import PGF.Binary
import PGF.Parsing.FCFG
import qualified PGF.Parsing.FCFG.Incremental as Incremental
@@ -193,6 +196,12 @@ categories :: PGF -> [Type]
-- definition is just for convenience.
startCat :: PGF -> Type
+-- | List of all functions defined in the abstract syntax
+functions :: PGF -> [CId]
+
+-- | The type of a given function
+functionType :: PGF -> CId -> Maybe Type
+
-- | Complete the last word in the given string. If the input
-- is empty or ends in whitespace, the last word is considred
-- to be the empty string. This means that the completions
@@ -272,6 +281,13 @@ categories pgf = [DTyp [] c [EMeta i | (Hyp _ _,i) <- zip hs [0..]] | (c,hs) <-
startCat pgf = DTyp [] (lookStartCat pgf) []
+functions pgf = Map.keys (funs (abstract pgf))
+
+functionType pgf fun =
+ case Map.lookup fun (funs (abstract pgf)) of
+ Just (ty,_,_) -> Just ty
+ Nothing -> Nothing
+
complete pgf from typ input =
let (ws,prefix) = tokensAndPrefix input
state0 = initState pgf from typ