mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 19:22:50 -06:00
SRGS: add top-level rules for each GF category.
This commit is contained in:
@@ -99,6 +99,11 @@ tableSet x y [] = [(x,y)]
|
|||||||
tableSet x y (p@(x',_):xs) | x' == x = (x,y):xs
|
tableSet x y (p@(x',_):xs) | x' == x = (x,y):xs
|
||||||
| otherwise = p:tableSet x y xs
|
| otherwise = p:tableSet x y xs
|
||||||
|
|
||||||
|
-- | Group tuples by their first elements.
|
||||||
|
buildMultiMap :: Ord a => [(a,b)] -> [(a,[b])]
|
||||||
|
buildMultiMap = map (\g -> (fst (head g), map snd g) )
|
||||||
|
. sortGroupBy (compareBy fst)
|
||||||
|
|
||||||
-- * equality functions
|
-- * equality functions
|
||||||
|
|
||||||
-- | Use an ordering function as an equality predicate.
|
-- | Use an ordering function as an equality predicate.
|
||||||
|
|||||||
@@ -57,13 +57,21 @@ prSrgsXml sisr (SRG{grammarName=name,startCat=start,
|
|||||||
++ ". " ++ "Original start category: " ++ origStart),
|
++ ". " ++ "Original start category: " ++ origStart),
|
||||||
meta "generator" ("Grammatical Framework " ++ version
|
meta "generator" ("Grammatical Framework " ++ version
|
||||||
++ " (compiled " ++ today ++ ")")]
|
++ " (compiled " ++ today ++ ")")]
|
||||||
++ map ruleToXML rs)
|
++ topCatRules
|
||||||
|
++ map ruleToXML rs)
|
||||||
ruleToXML (SRGRule cat origCat alts) =
|
ruleToXML (SRGRule cat origCat alts) =
|
||||||
rule (prCat cat) (comments ["Category " ++ origCat] ++ prRhs isList alts)
|
rule (prCat cat) (comments ["Category " ++ origCat] ++ prRhs isList alts)
|
||||||
where isList = "List" `isPrefixOf` origCat && length cs == 2
|
where isList = "List" `isPrefixOf` origCat && length cs == 2
|
||||||
&& isBase (cs!!0) && isCons (cs!!1)
|
&& isBase (cs!!0) && isCons (cs!!1)
|
||||||
cs = sortNub [f | SRGAlt _ (Name f _) _ <- alts]
|
cs = sortNub [f | SRGAlt _ (Name f _) _ <- alts]
|
||||||
prRhs isList rhss = [oneOf (map (mkProd sisr isList) rhss)]
|
prRhs isList rhss = [oneOf (map (mkProd sisr isList) rhss)]
|
||||||
|
-- externally visible rules for each of the GF categories
|
||||||
|
topCatRules = [topRule tc [oneOf (map it cs)] | (tc,cs) <- topCats]
|
||||||
|
where topCats = buildMultiMap [(gfCat origCat, cat) | SRGRule cat origCat _ <- rs]
|
||||||
|
gfCat = takeWhile (/='{')
|
||||||
|
it c = symItem [] (Cat c) 0
|
||||||
|
topRule i is = Tag "rule" [("id",i),("scope","public")]
|
||||||
|
(is ++ [tag ["$ = $$"]])
|
||||||
|
|
||||||
rule :: String -> [XML] -> XML
|
rule :: String -> [XML] -> XML
|
||||||
rule i = Tag "rule" [("id",i)]
|
rule i = Tag "rule" [("id",i)]
|
||||||
|
|||||||
Reference in New Issue
Block a user