summaryrefslogtreecommitdiff
path: root/src/runtime/haskell/PGF.hs
diff options
context:
space:
mode:
authorKrasimir Angelov <kr.angelov@gmail.com>2017-09-06 15:17:28 +0200
committerKrasimir Angelov <kr.angelov@gmail.com>2017-09-06 15:17:28 +0200
commitebe7cb3b73802c6c338b8f5cb9170aea970d231f (patch)
treed71639d792d78c9c8e3668ac5dab5ca41a133261 /src/runtime/haskell/PGF.hs
parent301b1009887440a76cd7022dbb53bda4211d49db (diff)
A new function called "completions" is added in the Haskell runtime and used in PGFService. This makes the extraction of completions more platform independent
Diffstat (limited to 'src/runtime/haskell/PGF.hs')
-rw-r--r--src/runtime/haskell/PGF.hs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/runtime/haskell/PGF.hs b/src/runtime/haskell/PGF.hs
index 83d9102c3..6c0002a8a 100644
--- a/src/runtime/haskell/PGF.hs
+++ b/src/runtime/haskell/PGF.hs
@@ -66,7 +66,7 @@ module PGF(
Forest.showBracketedString,flattenBracketedString,
-- ** Parsing
- parse, parseAllLang, parseAll, parse_, parseWithRecovery,
+ parse, parseAllLang, parseAll, parse_, parseWithRecovery, complete,
-- ** Evaluation
PGF.compute, paraphrase,
@@ -273,6 +273,25 @@ parse_ pgf lang typ dp s =
parseWithRecovery pgf lang typ open_typs dp s = Parse.parseWithRecovery pgf lang typ open_typs dp (words s)
+complete :: PGF -> Language -> Type -> String -> String -> (BracketedString,String,Map.Map Token [CId])
+complete pgf from typ input prefix =
+ let ws = words input
+ ps0 = Parse.initState pgf from typ
+ (ps,ws') = loop ps0 ws
+ bs = snd (Parse.getParseOutput ps typ Nothing)
+ in if not (null ws')
+ then (bs, unwords (if null prefix then ws' else ws'++[prefix]), Map.empty)
+ else (bs, prefix, fmap getFuns (Parse.getCompletions ps prefix))
+ where
+ loop ps [] = (ps,[])
+ loop ps (w:ws) = case Parse.nextState ps (Parse.simpleParseInput w) of
+ Left es -> (ps,w:ws)
+ Right ps -> loop ps ws
+
+ getFuns ps = [cid | (funid,cid,seq) <- snd . head $ Map.toList contInfo]
+ where
+ contInfo = Parse.getContinuationInfo ps
+
groupResults :: [[(Language,String)]] -> [(Language,[String])]
groupResults = Map.toList . foldr more Map.empty . start . concat
where