mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-04 16:52:50 -06:00
RunGHCC for testing
This commit is contained in:
57
src/GF/Canon/GFCC/RunGFCC.hs
Normal file
57
src/GF/Canon/GFCC/RunGFCC.hs
Normal file
@@ -0,0 +1,57 @@
|
||||
module Main where
|
||||
|
||||
import GF.Canon.GFCC.DataGFCC
|
||||
import GF.Canon.GFCC.AbsGFCC
|
||||
import GF.Canon.GFCC.ParGFCC
|
||||
import GF.Canon.GFCC.PrintGFCC
|
||||
import GF.Data.Operations
|
||||
import Data.Map
|
||||
import System
|
||||
|
||||
-- Simple translation application built on GFCC. AR 7/9/2006
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
file <- getLine ----getArgs
|
||||
grammar <- file2gfcc file
|
||||
loop grammar
|
||||
|
||||
loop :: GFCC -> IO ()
|
||||
loop grammar = do
|
||||
s <- getLine
|
||||
if s == "quit" then return () else do
|
||||
treat grammar s
|
||||
loop grammar
|
||||
|
||||
treat :: GFCC -> String -> IO ()
|
||||
treat grammar s = do
|
||||
let t = readExp s
|
||||
putStrLn $ printTree $ linExp grammar lang t
|
||||
putStrLn $ linearize grammar lang t
|
||||
where
|
||||
lang = head $ cncnames grammar
|
||||
|
||||
--- should be in an API
|
||||
|
||||
file2gfcc :: FilePath -> IO GFCC
|
||||
file2gfcc f =
|
||||
readFile f >>= err (error "no parse") (return . mkGFCC) . pGrammar . myLexer
|
||||
|
||||
readExp :: String -> Exp
|
||||
readExp = err (error "no parse") id . (pExp . myLexer)
|
||||
|
||||
|
||||
{-
|
||||
treat grammar s = putStrLn $ case comm of
|
||||
["lin"] -> unlines $ linearizeAll grammar $ readTree grammar rest
|
||||
["lin",lang] -> linearize grammar lang $ readTree grammar rest
|
||||
["parse",cat] -> unlines $ map showTree $ concat $ parseAll grammar cat rest
|
||||
["parse",lang,cat] -> unlines $ map showTree $ parse grammar lang cat rest
|
||||
["langs"] -> unwords $ languages grammar
|
||||
["cats"] -> unwords $ categories grammar
|
||||
["help"] -> helpMsg
|
||||
_ -> "command not interpreted: " ++ s
|
||||
where
|
||||
(comm,rest) = (words c,drop 1 r) where
|
||||
(c,r) = span (/=':') s
|
||||
-}
|
||||
Reference in New Issue
Block a user