summaryrefslogtreecommitdiff
path: root/src/GF/Formalism/Utilities.hs
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2006-06-08 21:23:29 +0000
committerkr.angelov <kr.angelov@gmail.com>2006-06-08 21:23:29 +0000
commit694f6eb984c8f22fe042e210b0671062accba8c7 (patch)
tree32faab2fafad6a46a4f2c2b1321dd51634749c1e /src/GF/Formalism/Utilities.hs
parent98d0af8d73ee56fdb9c64626e173eec0ebbce5e7 (diff)
code polishing for the literal category support
Diffstat (limited to 'src/GF/Formalism/Utilities.hs')
-rw-r--r--src/GF/Formalism/Utilities.hs30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/GF/Formalism/Utilities.hs b/src/GF/Formalism/Utilities.hs
index f89bbe4a9..0d303b175 100644
--- a/src/GF/Formalism/Utilities.hs
+++ b/src/GF/Formalism/Utilities.hs
@@ -112,7 +112,28 @@ inputMany toks = MkInput inEdges inBounds inFrom inTo inToken
-- | The values of the chart, a list of key-daughters pairs,
-- has unique keys. In essence, it is a map from 'n' to daughters.
-- The daughters should be a set (not necessarily sorted) of rhs's.
-type SyntaxChart n e = Assoc e [(n, [[e]])]
+type SyntaxChart n e = Assoc e [SyntaxNode n [e]]
+
+data SyntaxNode n e = SMeta
+ | SNode n [e]
+ | SString String
+ | SInt Integer
+ | SFloat Double
+ deriving (Eq,Ord)
+
+groupSyntaxNodes :: Ord n => [SyntaxNode n e] -> [SyntaxNode n [e]]
+groupSyntaxNodes [] = []
+groupSyntaxNodes (SNode n0 es0:xs) = (SNode n0 (es0:ess)) : groupSyntaxNodes xs'
+ where
+ (ess,xs') = span xs
+
+ span [] = ([],[])
+ span xs@(SNode n es:xs')
+ | n0 == n = let (ess,xs) = span xs' in (es:ess,xs)
+ | otherwise = ([],xs)
+groupSyntaxNodes (SString s:xs) = (SString s) : groupSyntaxNodes xs
+groupSyntaxNodes (SInt n:xs) = (SInt n) : groupSyntaxNodes xs
+groupSyntaxNodes (SFloat f:xs) = (SFloat f) : groupSyntaxNodes xs
-- better(?) representation of forests:
-- data Forest n = F (SMap n (SList [Forest n])) Bool
@@ -240,7 +261,12 @@ chart2forests :: (Ord n, Ord e) =>
chart2forests chart isMeta = concatMap edge2forests
where edge2forests edge = if isMeta edge then [FMeta]
else map item2forest $ chart ? edge
- item2forest (name, children) = FNode name $ children >>= mapM edge2forests
+ item2forest (SMeta) = FMeta
+ item2forest (SNode name children) = FNode name $ children >>= mapM edge2forests
+ item2forest (SString s) = FString s
+ item2forest (SInt n) = FInt n
+ item2forest (SFloat f) = FFloat f
+
{-
-- more intelligent(?) implementation,