From 115be3d52bb2fe522cb4a1aa5d27f2e7c4fba58e Mon Sep 17 00:00:00 2001 From: aarne Date: Fri, 25 Feb 2005 14:35:48 +0000 Subject: [PATCH] p by lines, lin to multi --- src/GF/Infra/Option.hs | 7 ++++--- src/GF/Shell.hs | 33 +++++++++++++++++++++++---------- src/GF/Shell/ShellCommands.hs | 10 +++++----- src/HelpFile | 6 +++++- src/HelpFile.hs | 12 ++++++++---- 5 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/GF/Infra/Option.hs b/src/GF/Infra/Option.hs index bac3aac6d..8ee49b68d 100644 --- a/src/GF/Infra/Option.hs +++ b/src/GF/Infra/Option.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/02/24 11:46:35 $ --- > CVS $Author: peb $ --- > CVS $Revision: 1.20 $ +-- > CVS $Date: 2005/02/25 15:35:48 $ +-- > CVS $Author: aarne $ +-- > CVS $Revision: 1.21 $ -- -- Options and flags used in GF shell commands and files. -- @@ -227,6 +227,7 @@ optimizeValues = iOpt "val" stripQualif = iOpt "strip" nostripQualif = iOpt "nostrip" showAll = iOpt "all" +showMulti = iOpt "multi" fromSource = iOpt "src" -- ** mainly for stand-alone diff --git a/src/GF/Shell.hs b/src/GF/Shell.hs index 252ad0249..9c22cdd14 100644 --- a/src/GF/Shell.hs +++ b/src/GF/Shell.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/02/24 11:46:37 $ --- > CVS $Author: peb $ --- > CVS $Revision: 1.33 $ +-- > CVS $Date: 2005/02/25 15:35:48 $ +-- > CVS $Author: aarne $ +-- > CVS $Revision: 1.34 $ -- -- GF shell command interpreter. ----------------------------------------------------------------------------- @@ -145,15 +145,28 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = checkOptions st co >> case comm of CPrintHistory -> (returnArg $ AString $ unlines $ reverse h) sa -- good to have here for piping; eh and ec must be done on outer level - CLinearize [] -> - changeArg (opTS2CommandArg (optLinearizeTreeVal opts gro) . s2t) sa + CLinearize [] + | oElem showMulti opts -> + changeArg (opTS2CommandArg (unlines. linearizeToAll + (allStateGrammars st)) . s2t) sa + | otherwise -> changeArg (opTS2CommandArg (optLinearizeTreeVal opts gro) . s2t) sa ---- CLinearize m -> changeArg (opTS2CommandArg (optLinearizeArgForm opts gro m)) sa - CParse -> do - warnDiscont opts - case optParseArgErrMsg opts gro (prCommandArg a) of - Ok (ts,msg) -> putStrLnFlush msg >> changeArg (const $ ATrms ts) sa - Bad msg -> changeArg (const $ AError msg) sa + CParse +---- | oElem showMulti opts -> do + | oElem byLines opts -> do + let ss = (if oElem showAll opts then id else filter (not . null)) $ lines $ prCommandArg a + mts <- mapM parse ss + let a' = ATrms [t | (_,ATrms ts) <- mts, t <- ts] + changeArg (const a') sa + | otherwise -> parse $ prCommandArg a + where + parse x = do + warnDiscont opts + let p = optParseArgErrMsg opts gro x + case p of + Ok (ts,msg) -> putStrLnFlush msg >> changeArg (const $ ATrms ts) sa + Bad msg -> changeArg (const $ AError (msg +++ "input" +++ x)) sa CTranslate il ol -> do let a' = opST2CommandArg (optParseArgErr opts (sgr il)) a diff --git a/src/GF/Shell/ShellCommands.hs b/src/GF/Shell/ShellCommands.hs index a2ef91eab..89aae2d06 100644 --- a/src/GF/Shell/ShellCommands.hs +++ b/src/GF/Shell/ShellCommands.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/02/24 11:46:37 $ --- > CVS $Author: peb $ --- > CVS $Revision: 1.23 $ +-- > CVS $Date: 2005/02/25 15:35:48 $ +-- > CVS $Author: aarne $ +-- > CVS $Revision: 1.24 $ -- -- The datatype of shell commands and the list of their options. ----------------------------------------------------------------------------- @@ -157,8 +157,8 @@ optionsOfCommand co = case co of CStripState -> none CTransformGrammar _ -> flags "printer" CConvertLatex _ -> none - CLinearize _ -> both "utf8 table struct record all" "lang number unlexer" - CParse -> both "new n ign raw v" "cat lang lexer parser number rawtrees" + CLinearize _ -> both "utf8 table struct record all multi" "lang number unlexer" + CParse -> both "new n ign raw v lines all" "cat lang lexer parser number rawtrees" CTranslate _ _ -> opts "cat lexer parser" CGenerateRandom -> flags "cat lang number depth" CGenerateTrees -> both "metas" "depth alts cat lang number" diff --git a/src/HelpFile b/src/HelpFile index 4b54bd0a6..4283164df 100644 --- a/src/HelpFile +++ b/src/HelpFile @@ -127,6 +127,7 @@ l, linearize: l PattList? Tree -struct bracketed form -record record, i.e. explicit GF concrete syntax term -all show all forms and variants + -multi linearize to all languages (the other options don't work) flags: -lang linearize in this grammar -number give this number of forms at most @@ -144,6 +145,8 @@ p, parse: p String -raw return context-free terms in raw form -v verbose: give more information if parsing fails -new use an experimental method (GF 2.0; sometimes very good) + -lines parse each line of input separately, ignoring empty lines + -all as -lines, but also parse empty lines flags: -cat parse in this category -lang parse in this grammar @@ -151,7 +154,8 @@ p, parse: p String -parser use this context-free parsing method -number return this many results at most examples: - p -cat=S -new "jag är gammal" -- print an S with the new method + p -cat=S -new "jag är gammal" -- parse an S with the new method + rf examples.txt | p -lines -- parse each non-empty line of the file tt, test_tokenizer: tt String Show the token list sent to the parser when String is parsed. diff --git a/src/HelpFile.hs b/src/HelpFile.hs index 94a479c58..10f350128 100644 --- a/src/HelpFile.hs +++ b/src/HelpFile.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date $ --- > CVS $Author $ --- > CVS $Revision $ +-- > CVS $Date: 2005/02/25 15:35:48 $ +-- > CVS $Author: aarne $ +-- > CVS $Revision: 1.25 $ -- -- Help on shell commands. Generated from HelpFile by 'make help'. -- PLEASE DON'T EDIT THIS FILE. @@ -156,6 +156,7 @@ txtHelpFile = "\n -struct bracketed form" ++ "\n -record record, i.e. explicit GF concrete syntax term" ++ "\n -all show all forms and variants" ++ + "\n -multi linearize to all languages (the other options don't work)" ++ "\n flags:" ++ "\n -lang linearize in this grammar" ++ "\n -number give this number of forms at most" ++ @@ -173,6 +174,8 @@ txtHelpFile = "\n -raw return context-free terms in raw form" ++ "\n -v verbose: give more information if parsing fails" ++ "\n -new use an experimental method (GF 2.0; sometimes very good)" ++ + "\n -lines parse each line of input separately, ignoring empty lines" ++ + "\n -all as -lines, but also parse empty lines" ++ "\n flags:" ++ "\n -cat parse in this category" ++ "\n -lang parse in this grammar" ++ @@ -180,7 +183,8 @@ txtHelpFile = "\n -parser use this context-free parsing method" ++ "\n -number return this many results at most" ++ "\n examples:" ++ - "\n p -cat=S -new \"jag är gammal\" -- print an S with the new method" ++ + "\n p -cat=S -new \"jag är gammal\" -- parse an S with the new method" ++ + "\n rf examples.txt | p -lines -- parse each non-empty line of the file" ++ "\n" ++ "\ntt, test_tokenizer: tt String" ++ "\n Show the token list sent to the parser when String is parsed." ++