diff options
| author | aarne <aarne@cs.chalmers.se> | 2006-10-02 19:16:38 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2006-10-02 19:16:38 +0000 |
| commit | 2f284deb1ce3071b86efcabb5e57028cc5d2c52f (patch) | |
| tree | 8253656660c9c4e36dc21bd7fe4f29d132f599f5 /src/GF/Canon/CanonToGFCC.hs | |
| parent | 514f732d16f0c0d3bd87f14431dc468040141590 (diff) | |
gfcc.txt almost ready
Diffstat (limited to 'src/GF/Canon/CanonToGFCC.hs')
| -rw-r--r-- | src/GF/Canon/CanonToGFCC.hs | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/GF/Canon/CanonToGFCC.hs b/src/GF/Canon/CanonToGFCC.hs index da40b8718..965e3fe55 100644 --- a/src/GF/Canon/CanonToGFCC.hs +++ b/src/GF/Canon/CanonToGFCC.hs @@ -12,7 +12,7 @@ -- GFC to GFCC compiler. AR Aug-Oct 2006 ----------------------------------------------------------------------------- -module GF.Canon.CanonToGFCC (prCanon2gfcc) where +module GF.Canon.CanonToGFCC (prCanon2gfcc, prCanon2f_gfcc) where import GF.Canon.AbsGFC import qualified GF.Canon.GFC as GFC @@ -30,6 +30,11 @@ import qualified GF.Infra.Modules as M import qualified GF.Infra.Option as O import GF.UseGrammar.Linear (expandLinTables, unoptimizeCanon) +-- these are needed for FCFG printing and might be moved +import GF.FCFG.ToFCFG (printFGrammar) +import GF.Conversion.GFC (gfc2fcfg) +import GF.Infra.Option (noOptions) + import GF.Infra.Ident import GF.Data.Operations import GF.Text.UTF8 @@ -44,12 +49,25 @@ prCanon2gfcc :: CanonGrammar -> String prCanon2gfcc = Pr.printTree . canon2gfcc . reorder . utf8Conv . canon2canon . normalize +-- print FCFG corresponding to the GFCC +prCanon2f_gfcc :: CanonGrammar -> String +prCanon2f_gfcc = + unlines . map printFGrammar . toFCFG . + reorder . utf8Conv . canon2canon . normalizeNoOpt + where + toFCFG cgr@(M.MGrammar (am:cms)) = + [gfc2fcfg noOptions (M.MGrammar [am,cm],c) | cm@(c,_) <- cms] +-- gfc2fcfg :: Options -> (CanonGrammar, Ident) -> FGrammar + -- This is needed to reorganize the grammar. GFCC has its own back-end optimization. -- But we need to have the canonical order in tables, created by valOpt normalize :: CanonGrammar -> CanonGrammar normalize = share . unoptimizeCanon . Sub.unSubelimCanon where share = M.MGrammar . map (shareModule valOpt) . M.modules --- allOpt +-- for FCFG generation +normalizeNoOpt = unoptimizeCanon . Sub.unSubelimCanon + -- Generate GFCC from GFCM. -- this assumes a grammar translated by canon2canon @@ -115,20 +133,10 @@ reorder cg = M.MGrammar $ cncs = sortBy (\ (x,_) (y,_) -> compare x y) [(lang, concr lang) | lang <- M.allConcretes cg abs] concr la = sortBy (\ (f,_) (g,_) -> compare f g) - [finfo | + [changeTyp finfo | (i,mo) <- mos, M.isModCnc mo, elem i (M.allExtends cg la), finfo <- tree2list (M.jments mo)] --- one grammar per language - needed for symtab generation -repartition :: CanonGrammar -> [CanonGrammar] -repartition cg = [M.partOfGrammar cg (lang,mo) | - let abs = maybe (error "no abstract") id $ M.greatestAbstract cg, - let mos = M.allModMod cg, - lang <- M.allConcretes cg abs, - let mo = errVal - (error ("no module found for " ++ A.prt lang)) $ M.lookupModule cg lang - ] - -- convert to UTF8 if not yet converted utf8Conv :: CanonGrammar -> CanonGrammar utf8Conv = M.MGrammar . map toUTF8 . M.modules where |
