From b037cbc361da5933e7c37f0117e46fbc07d2594f Mon Sep 17 00:00:00 2001 From: krasimir Date: Tue, 12 May 2009 20:52:18 +0000 Subject: added command ai which prints information about given identifier --- src/GF/Command/Commands.hs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/GF/Command/Commands.hs') diff --git a/src/GF/Command/Commands.hs b/src/GF/Command/Commands.hs index 7534554de..8f82b468f 100644 --- a/src/GF/Command/Commands.hs +++ b/src/GF/Command/Commands.hs @@ -35,6 +35,7 @@ import GF.Text.Coding import Data.Maybe import qualified Data.Map as Map import System.Cmd +import Text.PrettyPrint import Debug.Trace @@ -586,6 +587,30 @@ allCommands cod env@(pgf, mos) = Map.fromList [ ("append","append to file, instead of overwriting it") ], flags = [("file","the output filename")] + }), + ("ai", emptyCommandInfo { + longname = "abstract_info", + syntax = "ai IDENTIFIER", + synopsis = "provides an information about a function or a category from the abstract syntax", + explanation = unlines [ + "The command has one argument which is either function or a category defined in", + "the abstract syntax of the current grammar. If the argument is a function then", + "its type is printed out. If it is a category then the category definition is printed" + ], + exec = \opts arg -> do + case arg of + [Fun id []] -> case Map.lookup id (funs (abstract pgf)) of + Just (ty,def) -> putStrLn (render (text "fun" <+> text (prCId id) <+> colon <+> ppType 0 ty $$ + if def == EEq [] + then empty + else text "def" <+> text (prCId id) <+> char '=' <+> ppExpr 0 def)) + Nothing -> case Map.lookup id (cats (abstract pgf)) of + Just hyps -> putStrLn (render (text "cat" <+> + text (prCId id) <+> + hsep (map ppHypo hyps))) + Nothing -> putStrLn "unknown identifier" + _ -> putStrLn "a single identifier is expected from the command" + return void }) ] where -- cgit v1.2.3