1
0
forked from GitHub/gf-core

added command c-bracketedLinearize

This commit is contained in:
krangelov
2019-02-26 15:16:36 +01:00
parent a928e4657e
commit 2fdfef13d8

View File

@@ -153,6 +153,8 @@ cpgfMain qsem command (t,(pgf,pc)) =
"c-parse" -> withQSem qsem $
out t=<< join (parse # input % start % limit % treeopts)
"c-linearize" -> out t=<< lin # tree % to
"c-bracketedLinearize"
-> out t=<< bracketedLin # tree % to
"c-linearizeAll"-> out t=<< linAll # tree % to
"c-translate" -> withQSem qsem $
out t=<<join(trans # input % to % start % limit%treeopts)
@@ -224,6 +226,10 @@ cpgfMain qsem command (t,(pgf,pc)) =
lin' tree (tos,unlex) =
[makeObj ["to".=to,"text".=unlex (C.linearize c tree)]|(to,c)<-tos]
bracketedLin tree to = showJSON (lin' tree to)
bracketedLin' tree (tos,unlex) =
[makeObj ["to".=to,"brackets".=showJSON (C.bracketedLinearize c tree)]|(to,c)<-tos]
trans input@((from,_),_) to start mlimit (trie,jsontree) =
do parses <- parse' start mlimit input
return $
@@ -978,6 +984,15 @@ instance JSON PGF.BracketedString where
makeObj ["cat".=cat, "fid".=fid, "index".=index, "fun".=fun, "children".=bs]
showJSON (PGF.Leaf s) = makeObj ["token".=s]
#if C_RUNTIME
instance JSON C.BracketedString where
readJSON x = return (C.Leaf "")
showJSON (C.Bracket cat fid index fun bs) =
makeObj ["cat".=cat, "fid".=fid, "index".=index, "fun".=fun, "children".=bs]
showJSON C.BIND = makeObj ["bind".=True]
showJSON (C.Leaf s) = makeObj ["token".=s]
#endif
-- * PGF utilities
{-
cat :: PGF -> Maybe PGF.Type -> PGF.Type