forked from GitHub/gf-core
+ References to modules under src/compiler have been eliminated from the PGF library (under src/runtime/haskell). Only two functions had to be moved (from GF.Data.Utilities to PGF.Utilities) to make this possible, other apparent dependencies turned out to be vacuous. + In gf.cabal, the GF executable no longer directly depends on the PGF library source directory, but only on the exposed library modules. This means that there is less duplication in gf.cabal and that the 30 modules in the PGF library will no longer be compiled twice while building GF. To make this possible, additional PGF library modules have been exposed, even though they should probably be considered for internal use only. They could be collected in a PGF.Internal module, or marked as "unstable", to make this explicit. + Also, by using the -fwarn-unused-imports flag, ~220 redundant imports were found and removed, reducing the total number of imports by ~15%.
37 lines
1.1 KiB
Haskell
37 lines
1.1 KiB
Haskell
{--
|
|
This module provide a function for indexing a pgf.
|
|
|
|
It reads the pgf and add a global flag, called "index", containing a string
|
|
with concrete names and size in bytes separated by a column.
|
|
ex : "DisambPhrasebookEng:18778 PhrasebookBul:49971 PhrasebookCat:32738..."
|
|
--}
|
|
module GF.Index (addIndex) where
|
|
|
|
import PGF
|
|
import PGF.Data
|
|
--import PGF.Binary
|
|
import Data.Binary
|
|
import Data.ByteString.Lazy (length) -- readFile
|
|
import qualified Data.Map as Map
|
|
import Data.Map (toAscList)
|
|
import Data.List (intercalate)
|
|
--import qualified Data.ByteString.Lazy as BS
|
|
|
|
addIndex :: PGF -> PGF
|
|
addIndex pgf = pgf {gflags = flags}
|
|
where flags = Map.insert (mkCId "index") (LStr $ showIndex index) (gflags pgf)
|
|
index = getIndex pgf
|
|
|
|
|
|
showIndex :: [(String,Int)] -> String
|
|
showIndex = intercalate " " . map f
|
|
where f (name,size) = name ++ ":" ++ show size
|
|
|
|
getsize :: Binary a => a -> Int
|
|
getsize x = let bs = encode x in fromIntegral $ Data.ByteString.Lazy.length bs
|
|
|
|
getIndex :: PGF -> [(String,Int)]
|
|
getIndex pgf = cncindex
|
|
where cncindex = map f $ Data.Map.toAscList $ concretes pgf
|
|
f (cncname,cnc) = (show cncname, getsize cnc)
|