{- Copyright 2010 Dominique Devriese
This file is part of the grammar-combinators library.
The grammar-combinators library is free software: you can
redistribute it and/or modify it under the terms of the GNU
Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at
your option) any later version.
Foobar is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with Foobar. If not, see
<http://www.gnu.org/licenses/>.
-}{-# LANGUAGE FlexibleContexts #-}{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE GADTs #-}{-# LANGUAGE KindSignatures #-}{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE RankNTypes #-}{-# LANGUAGE ScopedTypeVariables #-}moduleText.GrammarCombinators.Transform.CombineEpsilons(combineEpsilons,combineEpsilonsE)whereimportText.GrammarCombinators.BasedataCombineEpsilonsRulep(phi::*->*)(r::*->*)tvwhereCERule::(v'->v)->pv'->CombineEpsilonsRulepphirtvCEEpsRule::v->CombineEpsilonsRulepphirtvinstance(ProductionRulep,EpsProductionRulep)=>ProductionRule(CombineEpsilonsRulepphirt)whereendOfInput=CERuleidendOfInput(CEEpsRuleva)>>>(CEEpsRulevb)=CEEpsRule$vavb(CEEpsRuleva)>>>(CERulefbrb)=CERule(va.fb)rb(CERulefara)>>>(CEEpsRulevb)=CERule(flip($)vb.fa)ra(CERulefara)>>>(CERulefbrb)=CERule(uncurryfa)((\vavb->(va,fbvb))$>>ra>>>rb)ra|||rb=CERuleid$runCERulera|||runCERulerbdie=CERuleiddieinstance(EpsProductionRulep)=>EpsProductionRule(CombineEpsilonsRulepphirt)whereepsilon=CEEpsRuleinstance(EpsProductionRulep)=>LiftableProductionRule(CombineEpsilonsRulepphirt)whereepsilonLv_=CEEpsRulevinstance(TokenProductionRulept)=>TokenProductionRule(CombineEpsilonsRulepphirt)twheretoken=CERuleid.tokenanyToken=CERuleidanyTokeninstance(RecProductionRulepphir)=>RecProductionRule(CombineEpsilonsRulepphirt)phirwhereref=CERuleid.refinstance(EpsProductionRulep,LoopProductionRulepphir)=>LoopProductionRule(CombineEpsilonsRulepphirt)phirwheremanyRef=CERuleid.manyRefmany1Ref=CERuleid.many1RefrunCERule::(ProductionRulep,EpsProductionRulep)=>CombineEpsilonsRulepphirtv->pvrunCERule(CERulefr)=f$>>rrunCERule(CEEpsRulev)=epsilonv-- | Combine consecutive epsilon rules in a given grammar into a single-- epsilon rule.combineEpsilons::forallphitrrr.GContextFreeGrammarphitrrr->GContextFreeGrammarphitrrrcombineEpsilonsgramidx=runCERule$gramidx-- | Combine consecutive epsilon rules in a given extended -- grammar into a single epsilon rule.combineEpsilonsE::forallphitrrr.GExtendedContextFreeGrammarphitrrr->GExtendedContextFreeGrammarphitrrrcombineEpsilonsEgramidx=runCERule$gramidx