forked from GitHub/gf-core
add functions and functionType to the PGF API
This commit is contained in:
18
src/PGF.hs
18
src/PGF.hs
@@ -27,6 +27,9 @@ module PGF(
|
|||||||
showType, readType,
|
showType, readType,
|
||||||
categories, startCat,
|
categories, startCat,
|
||||||
|
|
||||||
|
-- * Functions
|
||||||
|
functions, functionType,
|
||||||
|
|
||||||
-- * Expressions
|
-- * Expressions
|
||||||
-- ** Identifiers
|
-- ** Identifiers
|
||||||
CId, mkCId, prCId, wildCId,
|
CId, mkCId, prCId, wildCId,
|
||||||
@@ -65,7 +68,7 @@ import PGF.Generate
|
|||||||
import PGF.TypeCheck
|
import PGF.TypeCheck
|
||||||
import PGF.Paraphrase
|
import PGF.Paraphrase
|
||||||
import PGF.Macros
|
import PGF.Macros
|
||||||
import PGF.Data
|
import PGF.Data hiding (functions)
|
||||||
import PGF.Binary
|
import PGF.Binary
|
||||||
import PGF.Parsing.FCFG
|
import PGF.Parsing.FCFG
|
||||||
import qualified PGF.Parsing.FCFG.Incremental as Incremental
|
import qualified PGF.Parsing.FCFG.Incremental as Incremental
|
||||||
@@ -193,6 +196,12 @@ categories :: PGF -> [Type]
|
|||||||
-- definition is just for convenience.
|
-- definition is just for convenience.
|
||||||
startCat :: PGF -> Type
|
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
|
-- | Complete the last word in the given string. If the input
|
||||||
-- is empty or ends in whitespace, the last word is considred
|
-- is empty or ends in whitespace, the last word is considred
|
||||||
-- to be the empty string. This means that the completions
|
-- 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) []
|
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 =
|
complete pgf from typ input =
|
||||||
let (ws,prefix) = tokensAndPrefix input
|
let (ws,prefix) = tokensAndPrefix input
|
||||||
state0 = initState pgf from typ
|
state0 = initState pgf from typ
|
||||||
|
|||||||
Reference in New Issue
Block a user