summaryrefslogtreecommitdiff
path: root/src/runtime/haskell-bind/test.hs
blob: 1c0c9fa87e3ea844561eb2b6c07ad05848b51bd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import PGF2
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M

main :: IO ()
main = do
  pgf <- readPGF "/Users/john/repositories/GF/contrib/foods/Foods.pgf"
  let
    Just concr = M.lookup "FoodsEng" (languages pgf)
    loop = do
      putStr "> "
      input <- getLine
      let
        (sent,pfx) =
          if C.isSpace (last input)
          then (input, "")
          else let toks = words input in (unwords (init toks), last toks)
      let pr = complete concr (startCat pgf) sent pfx Nothing
      case pr of
        ParseOk x -> print x
        ParseFailed x s -> putStrLn $ "parse failed at " ++ show x ++ " " ++ s
        ParseIncomplete -> putStrLn "input incomplete"
      loop
  loop