mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
Also remove indirectly cyclic productions.
This commit is contained in:
@@ -89,9 +89,17 @@ stateGFCC = mkGFCC . mkCanon2gfcc . stateGrammarST
|
|||||||
-- * Grammar filtering
|
-- * Grammar filtering
|
||||||
|
|
||||||
-- | Removes all directly and indirectly cyclic productions.
|
-- | Removes all directly and indirectly cyclic productions.
|
||||||
|
-- FIXME: this may be too aggressive, only one production
|
||||||
|
-- needs to be removed to break a given cycle. But which
|
||||||
|
-- one should we pick?
|
||||||
|
-- FIXME: Does not (yet) remove productions which are cyclic
|
||||||
|
-- because of empty productions.
|
||||||
removeCycles :: CFRules -> CFRules
|
removeCycles :: CFRules -> CFRules
|
||||||
removeCycles = groupProds . removeCycles_ . ungroupProds
|
removeCycles = groupProds . f . ungroupProds
|
||||||
where removeCycles_ rs = [r | r@(CFRule c rhs _) <- rs, rhs /= [Cat c]]
|
where f rs = filter (not . isCycle) rs
|
||||||
|
where alias = transitiveClosure $ mkRel [(c,c') | CFRule c [Cat c'] _ <- rs]
|
||||||
|
isCycle (CFRule c [Cat c'] _) = isRelatedTo alias c' c
|
||||||
|
isCycle _ = False
|
||||||
|
|
||||||
-- | Removes productions which use categories which have no productions.
|
-- | Removes productions which use categories which have no productions.
|
||||||
-- Only does one pass through the grammar.
|
-- Only does one pass through the grammar.
|
||||||
|
|||||||
Reference in New Issue
Block a user