mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-24 03:52:50 -06:00
added function lengthBracketedString
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
|
|
||||||
module PGF.Forest( Forest(..)
|
module PGF.Forest( Forest(..)
|
||||||
, BracketedString, showBracketedString
|
, BracketedString, showBracketedString, lengthBracketedString
|
||||||
, linearizeWithBrackets
|
, linearizeWithBrackets
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
|||||||
@@ -240,6 +240,11 @@ showBracketedString = render . ppBracketedString
|
|||||||
ppBracketedString (Leaf t) = text t
|
ppBracketedString (Leaf t) = text t
|
||||||
ppBracketedString (Bracket cat fcat index bss) = parens (ppCId cat <+> hsep (map ppBracketedString bss))
|
ppBracketedString (Bracket cat fcat index bss) = parens (ppCId cat <+> hsep (map ppBracketedString bss))
|
||||||
|
|
||||||
|
-- | The length of the bracketed string in number of tokens.
|
||||||
|
lengthBracketedString :: BracketedString -> Int
|
||||||
|
lengthBracketedString (Leaf _) = 1
|
||||||
|
lengthBracketedString (Bracket _ _ _ bss) = sum (map lengthBracketedString bss)
|
||||||
|
|
||||||
untokn :: String -> BracketedTokn -> (String,[BracketedString])
|
untokn :: String -> BracketedTokn -> (String,[BracketedString])
|
||||||
untokn nw (LeafKS ts) = (head ts,map Leaf ts)
|
untokn nw (LeafKS ts) = (head ts,map Leaf ts)
|
||||||
untokn nw (LeafKP d vs) = let ts = sel d vs nw
|
untokn nw (LeafKP d vs) = let ts = sel d vs nw
|
||||||
|
|||||||
Reference in New Issue
Block a user