PGF Service: add an option to return syntax trees in JSON format

The parse/translate/c-parse/c-translate commands now recognize the option
jsontree=true to augment the returned JSON structure with a field called
"jsontree" next to the field "tree", or "jsontrees" next to "trees",
containing the the returned syntax tree in JSON format (the same format
returned by the abstrjson command, similar to the format returned in the
"brackets" field).
This commit is contained in:
hallgren
2015-03-24 17:37:43 +00:00
parent 2041578406
commit 6d72126ffc
2 changed files with 52 additions and 26 deletions

View File

@@ -349,12 +349,12 @@ browse pgf id = fmap (\def -> (def,producers,consumers)) definition
expIds _ ids = ids
-- | A type for plain applicative trees
data ATree = Other Tree | App CId [ATree] deriving Show
data Trie = Oth Tree | Ap CId [[Trie ]] deriving Show
data ATree t = Other t | App CId [ATree t] deriving Show
data Trie = Oth Tree | Ap CId [[Trie ]] deriving Show
-- ^ A type for tries of plain applicative trees
-- | Convert a 'Tree' to an 'ATree'
toATree :: Tree -> ATree
toATree :: Tree -> ATree Tree
toATree e = maybe (Other e) app (unApp e)
where
app (f,es) = App f (map toATree es)