diff options
| author | hallgren <hallgren@chalmers.se> | 2015-08-26 13:56:23 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2015-08-26 13:56:23 +0000 |
| commit | 128236eab9f24f7085e1378d3f78306d9cad0658 (patch) | |
| tree | 9d8f0647a8006385fdaf6862769650c52e3a1b2e /src/compiler/GF/Data/Operations.hs | |
| parent | 32d5d4b52f37b8c421291a0cd8b77ada8d71fac2 (diff) | |
GF shell: change parse & linearize to obtain useful results from p|l and l|p in more cases
These changes are inspired by the gf -cshell implementation of these commands.
The output of the linearize command has been changed to remove superfluous
blank lines and commas, and deliver the result as a list of strings instead of
a single multi-line string. This makes it possible to use -all and pipe the
results to the parse command. This also means that with -treebank -all,
the language tag will be repeated for each result from the same language.
The parse command, when trying to parse with more than one language, would
"forget" other results after a failed parse, and thus not send all
successful parses through the pipe. For example, if English is not the first
language in the grammar,
p "hello" | l
would output nothing, instead of translations of "hello" to all languages,
forcing the user to write
p -lang=Eng "hello" | l
instead, to get the expected result. The cause of this behaviour was in the
function fromParse, which was rather messy, so I assume it is not intentional,
but the result of a programming mistake at some point.
The fromParse function has now been refactored from a big recursive function
into
fromParse opts = foldr (joinPiped . fromParse1 opts) void
where the helper functions fromParse1 deals with a single parse result and
joinPiped combines multiple parse results.
Diffstat (limited to 'src/compiler/GF/Data/Operations.hs')
| -rw-r--r-- | src/compiler/GF/Data/Operations.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/compiler/GF/Data/Operations.hs b/src/compiler/GF/Data/Operations.hs index 52632c163..3c8b16b8a 100644 --- a/src/compiler/GF/Data/Operations.hs +++ b/src/compiler/GF/Data/Operations.hs @@ -38,7 +38,7 @@ module GF.Data.Operations ( tree2list, -- ** Printing - indent, (+++), (++-), (++++), (+++++), + indent, (+++), (++-), (++++), (+++-), (+++++), prUpper, prReplicate, prTList, prQuotedString, prParenth, prCurly, prBracket, prArgList, prSemicList, prCurlyList, restoreEscapes, numberedParagraphs, prConjList, prIfEmpty, wrapLines, @@ -160,13 +160,20 @@ tree2list = Map.toList indent :: Int -> String -> String indent i s = replicate i ' ' ++ s -(+++), (++-), (++++), (+++++) :: String -> String -> String +(+++), (++-), (++++), (+++-), (+++++) :: String -> String -> String a +++ b = a ++ " " ++ b + a ++- "" = a a ++- b = a +++ b + a ++++ b = a ++ "\n" ++ b + +a +++- "" = a +a +++- b = a ++++ b + a +++++ b = a ++ "\n\n" ++ b + prUpper :: String -> String prUpper s = s1 ++ s2' where (s1,s2) = span isSpace s |
