diff options
| author | krasimir <krasimir@chalmers.se> | 2008-06-19 12:48:29 +0000 |
|---|---|---|
| committer | krasimir <krasimir@chalmers.se> | 2008-06-19 12:48:29 +0000 |
| commit | 4dd62417dc64609e0c37633fbbba52e82c221b2e (patch) | |
| tree | ba6404c44f7f681c40a7dea5521243f0ede9c752 /src-3.0/GF/Command | |
| parent | 944eea8de9e077d1b3ee1a9edad9c52e9dbc2bd0 (diff) | |
split the Exp type to Tree and Expr
Diffstat (limited to 'src-3.0/GF/Command')
| -rw-r--r-- | src-3.0/GF/Command/Abstract.hs | 2 | ||||
| -rw-r--r-- | src-3.0/GF/Command/Commands.hs | 26 | ||||
| -rw-r--r-- | src-3.0/GF/Command/Interpreter.hs | 24 | ||||
| -rw-r--r-- | src-3.0/GF/Command/Parse.hs | 6 |
4 files changed, 29 insertions, 29 deletions
diff --git a/src-3.0/GF/Command/Abstract.hs b/src-3.0/GF/Command/Abstract.hs index 8643a649f..b26499d54 100644 --- a/src-3.0/GF/Command/Abstract.hs +++ b/src-3.0/GF/Command/Abstract.hs @@ -24,7 +24,7 @@ data Value deriving (Eq,Ord,Show) data Argument - = AExp Exp + = ATree Tree | ANoArg | AMacro Ident deriving (Eq,Ord,Show) diff --git a/src-3.0/GF/Command/Commands.hs b/src-3.0/GF/Command/Commands.hs index b66d4764d..27c8e5fb4 100644 --- a/src-3.0/GF/Command/Commands.hs +++ b/src-3.0/GF/Command/Commands.hs @@ -20,7 +20,7 @@ import GF.Compile.Export import GF.Infra.Option (noOptions) import GF.Infra.UseIO import GF.Data.ErrM ---- -import PGF.ExprSyntax (readExp) +import PGF.Expr (readTree) import GF.Command.Abstract import GF.Text.Lexing import GF.Text.Transliterations @@ -29,12 +29,12 @@ import GF.Data.Operations import Data.Maybe import qualified Data.Map as Map -import System +import System.Cmd -type CommandOutput = ([Exp],String) ---- errors, etc +type CommandOutput = ([Tree],String) ---- errors, etc data CommandInfo = CommandInfo { - exec :: [Option] -> [Exp] -> IO CommandOutput, + exec :: [Option] -> [Tree] -> IO CommandOutput, synopsis :: String, syntax :: String, explanation :: String, @@ -192,7 +192,7 @@ allCommands pgf = Map.fromList [ ("full","give full information of the commands") ], exec = \opts ts -> return ([], case ts of - [t] -> let co = showExp t in + [t] -> let co = showTree t in case lookCommand co (allCommands pgf) of ---- new map ??!! Just info -> commandHelp True (co,info) _ -> "command not found" @@ -381,9 +381,9 @@ allCommands pgf = Map.fromList [ s <- readFile file return $ case opts of _ | isOpt "lines" opts && isOpt "tree" opts -> - fromTrees [t | l <- lines s, Just t <- [readExp l]] + fromTrees [t | l <- lines s, Just t <- [readTree l]] _ | isOpt "tree" opts -> - fromTrees [t | Just t <- [readExp s]] + fromTrees [t | Just t <- [readTree s]] _ | isOpt "lines" opts -> fromStrings $ lines s _ -> fromString s, flags = [("file","the input file name")] @@ -469,7 +469,7 @@ allCommands pgf = Map.fromList [ _ -> linearize pgf lang treebank opts t = unlines $ - (abstractName pgf ++ ": " ++ showExp t) : + (abstractName pgf ++ ": " ++ showTree t) : [lang ++ ": " ++ linear opts lang t | lang <- optLangs opts] optRestricted opts = restrictPGF (hasLin pgf (mkCId (optLang opts))) pgf @@ -483,11 +483,11 @@ allCommands pgf = Map.fromList [ optNum opts = valIntOpts "number" 1 opts optNumInf opts = valIntOpts "number" 1000000000 opts ---- 10^9 - fromTrees ts = (ts,unlines (map showExp ts)) - fromStrings ss = (map EStr ss, unlines ss) - fromString s = ([EStr s], s) - toStrings ts = [s | EStr s <- ts] - toString ts = unwords [s | EStr s <- ts] + fromTrees ts = (ts,unlines (map showTree ts)) + fromStrings ss = (map (Lit . LStr) ss, unlines ss) + fromString s = ([Lit (LStr s)], s) + toStrings ts = [s | Lit (LStr s) <- ts] + toString ts = unwords [s | Lit (LStr s) <- ts] prGrammar opts = case opts of _ | isOpt "cats" opts -> unwords $ categories pgf diff --git a/src-3.0/GF/Command/Interpreter.hs b/src-3.0/GF/Command/Interpreter.hs index ee354bd45..e1a06a205 100644 --- a/src-3.0/GF/Command/Interpreter.hs +++ b/src-3.0/GF/Command/Interpreter.hs @@ -24,7 +24,7 @@ data CommandEnv = CommandEnv { multigrammar :: PGF, commands :: Map.Map String CommandInfo, commandmacros :: Map.Map String CommandLine, - expmacros :: Map.Map String Exp + expmacros :: Map.Map String Tree } mkCommandEnv :: PGF -> CommandEnv @@ -64,18 +64,18 @@ interpretPipe env cs = do appLine es = map (map (appCommand es)) -- macro definition applications: replace ?i by (exps !! i) -appCommand :: [Exp] -> Command -> Command +appCommand :: [Tree] -> Command -> Command appCommand xs c@(Command i os arg) = case arg of - AExp e -> Command i os (AExp (app e)) - _ -> c + ATree e -> Command i os (ATree (app e)) + _ -> c where app e = case e of - EMeta i -> xs !! i - EApp f as -> EApp f (map app as) - EAbs x b -> EAbs x (app b) + Meta i -> xs !! i + Fun f as -> Fun f (map app as) + Abs x b -> Abs x (app b) -- return the trees to be sent in pipe, and the output possibly printed -interpret :: CommandEnv -> [Exp] -> Command -> IO CommandOutput +interpret :: CommandEnv -> [Tree] -> Command -> IO CommandOutput interpret env trees0 comm = case lookCommand co comms of Just info -> do checkOpts info @@ -100,17 +100,17 @@ interpret env trees0 comm = case lookCommand co comms of -- analyse command parse tree to a uniform datastructure, normalizing comm name --- the env is needed for macro lookup -getCommand :: CommandEnv -> Command -> [Exp] -> (String,[Option],[Exp]) +getCommand :: CommandEnv -> Command -> [Tree] -> (String,[Option],[Tree]) getCommand env co@(Command c opts arg) ts = (getCommandOp c,opts,getCommandArg env arg ts) -getCommandArg :: CommandEnv -> Argument -> [Exp] -> [Exp] +getCommandArg :: CommandEnv -> Argument -> [Tree] -> [Tree] getCommandArg env a ts = case a of AMacro m -> case Map.lookup m (expmacros env) of Just t -> [t] _ -> [] - AExp t -> [t] -- ignore piped - ANoArg -> ts -- use piped + ATree t -> [t] -- ignore piped + ANoArg -> ts -- use piped -- abbreviation convention from gf commands getCommandOp s = case break (=='_') s of diff --git a/src-3.0/GF/Command/Parse.hs b/src-3.0/GF/Command/Parse.hs index 1b603f411..eaf4cba84 100644 --- a/src-3.0/GF/Command/Parse.hs +++ b/src-3.0/GF/Command/Parse.hs @@ -1,7 +1,7 @@ module GF.Command.Parse(readCommandLine, pCommand) where -import PGF.ExprSyntax -import PGF.Data(Exp) +import PGF.Expr +import PGF.Data(Tree) import GF.Command.Abstract import Data.Char @@ -43,6 +43,6 @@ pFilename = liftM2 (:) (RP.satisfy isFileFirst) (RP.munch (not . isSpace)) where pArgument = RP.option ANoArg - (fmap AExp (pExp False) + (fmap ATree (pTree False) RP.<++ (RP.munch isSpace >> RP.char '%' >> fmap AMacro pIdent)) |
