1
0
forked from GitHub/gf-core

modernized parser in EmbedAPI

This commit is contained in:
aarne
2007-09-05 14:05:42 +00:00
parent 22b4069803
commit f357082c27
15 changed files with 335 additions and 87 deletions

View File

@@ -0,0 +1,23 @@
module Main where
import GF.Embed.EmbedAPI
import System (getArgs)
main :: IO ()
main = do
file:_ <- getArgs
gr <- file2grammar file
loop (translate gr)
loop :: (String -> String) -> IO ()
loop trans = do
s <- getLine
if s == "quit" then putStrLn "bye" else do
putStrLn $ trans s
loop trans
translate :: MultiGrammar -> String -> String
translate gr = unlines . map transLine . lines where
transLine s = case parseAllLang gr (startCat gr) s of
(lg,t:_):_ -> unlines [linearize gr l t | l <- languages gr, l /= lg]
_ -> "NO PARSE"