summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Command/Commands.hs
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2013-10-24 17:29:02 +0000
committerhallgren <hallgren@chalmers.se>2013-10-24 17:29:02 +0000
commit9410c6b1411612658d5262cbfca903fd1927cd55 (patch)
tree73fcc48ca2dc921c6082608da7ab63a64bf229d2 /src/compiler/GF/Command/Commands.hs
parentc2e977c67a99428694d0112e211b32e645b54bf8 (diff)
Functions merge trees into tries in the GF Shell and the PGF web service
* In the shell, the new command tt (to_trie) merges a list of trees into a trie and prints it in a readable way, where unique subtrees are marked with a "*" and alternative subtrees are marked with numbers. * In the PGF web service, adding the parameter trie=yes to the parse and translate commands augments the JSON output with a trie. Example to try in the shell: Phrasebook> p -lang=Eng "your son waits for you" | tt
Diffstat (limited to 'src/compiler/GF/Command/Commands.hs')
-rw-r--r--src/compiler/GF/Command/Commands.hs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/compiler/GF/Command/Commands.hs b/src/compiler/GF/Command/Commands.hs
index 8643f8a75..681b64f0d 100644
--- a/src/compiler/GF/Command/Commands.hs
+++ b/src/compiler/GF/Command/Commands.hs
@@ -687,6 +687,12 @@ allCommands = Map.fromList [
("to", "forward-apply transliteration defined in this file")
]
}),
+ ("tt", emptyCommandInfo {
+ longname = "to_trie",
+ syntax = "to_trie",
+ synopsis = "combine a list of trees into a trie",
+ exec = \ _ _ -> return . fromString . trie
+ }),
("pt", emptyCommandInfo {
longname = "put_tree",
syntax = "pt OPT? TREE",
@@ -1407,3 +1413,18 @@ execToktok (pgf, _) opts exprs = do
getLang [] = Nothing
getLang (OFlag "lang" (VId l):_) = readLanguage l
getLang (_:os) = getLang os
+
+
+
+trie = render . pptss . toTrie . map toATree
+ where
+ pptss [ts] = text "*"<+>nest 2 (ppts ts)
+ pptss tss = vcat [int i<+>nest 2 (ppts ts)|(i,ts)<-zip [1..] tss]
+
+ ppts = vcat . map ppt
+
+ ppt t =
+ case t of
+ Oth e -> text (showExpr [] e)
+ Ap f [[]] -> text (showCId f)
+ Ap f tss -> text (showCId f) $$ nest 2 (pptss tss)