forked from GitHub/gf-core
PGF library: expose only PGF and PGF.Internal instead of all modules
PGF exports the public, stable API. PGF.Internal exports additional things needed in the GF compiler & shell, including the nonstardard version of Data.Binary.
This commit is contained in:
9
gf.cabal
9
gf.cabal
@@ -76,7 +76,7 @@ Library
|
||||
|
||||
if flag(custom-binary)
|
||||
hs-source-dirs: src/binary
|
||||
exposed-modules:
|
||||
other-modules:
|
||||
-- not really part of GF but I have changed the original binary library
|
||||
-- and we have to keep the copy for now.
|
||||
Data.Binary
|
||||
@@ -95,14 +95,15 @@ Library
|
||||
|
||||
exposed-modules:
|
||||
PGF
|
||||
PGF.Internal
|
||||
PGF.Lexing
|
||||
PGF.Utilities
|
||||
other-modules:
|
||||
PGF.Data
|
||||
PGF.Macros
|
||||
PGF.Binary
|
||||
PGF.Optimize
|
||||
PGF.Printer
|
||||
PGF.Utilities
|
||||
PGF.Lexing
|
||||
other-modules:
|
||||
PGF.CId
|
||||
PGF.Expr
|
||||
PGF.Generate
|
||||
|
||||
@@ -14,14 +14,14 @@ import Prelude hiding (putStrLn)
|
||||
|
||||
import PGF
|
||||
|
||||
import PGF.Macros(lookStartCat,functionsToCat,lookValCat,restrictPGF,hasLin)
|
||||
import PGF.Data(abstract,funs,cats,Literal(LStr),Expr(EFun,ELit)) ----
|
||||
import PGF.Internal(lookStartCat,functionsToCat,lookValCat,restrictPGF,hasLin)
|
||||
import PGF.Internal(abstract,funs,cats,Literal(LStr),Expr(EFun,ELit)) ----
|
||||
--import PGF.Morphology(isInMorpho,morphoKnown)
|
||||
import PGF.Printer(ppFun,ppCat)
|
||||
import PGF.Internal(ppFun,ppCat)
|
||||
--import PGF.Probabilistic(rankTreesByProbs,probTree,setProbabilities)
|
||||
--import PGF.Generate (generateRandomFrom) ----
|
||||
--import PGF.Tree (Tree(Fun), expr2tree, tree2expr)
|
||||
import PGF.Optimize(optimizePGF)
|
||||
import PGF.Internal(optimizePGF)
|
||||
|
||||
import GF.Compile.Export
|
||||
import GF.Compile.ToAPI
|
||||
@@ -41,7 +41,7 @@ import GF.Command.TreeOperations ---- temporary place for typecheck and compute
|
||||
|
||||
import GF.Data.Operations
|
||||
|
||||
import Data.Binary (encodeFile)
|
||||
import PGF.Internal (encodeFile)
|
||||
import Data.List(intersperse,nub)
|
||||
import Data.Maybe
|
||||
import qualified Data.Map as Map
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
module GF.Command.Importing (importGrammar, importSource) where
|
||||
|
||||
import PGF
|
||||
import PGF.Data
|
||||
import PGF.Optimize
|
||||
import PGF.Internal(optimizePGF,unionPGF,msgUnionPGF)
|
||||
|
||||
import GF.Compile
|
||||
import GF.Compile.Multi (readMulti)
|
||||
|
||||
@@ -12,7 +12,7 @@ import GF.Command.Commands
|
||||
import GF.Command.Abstract
|
||||
import GF.Command.Parse
|
||||
import PGF
|
||||
import PGF.Data
|
||||
import PGF.Internal
|
||||
--import PGF.Morphology
|
||||
import GF.Infra.SIO
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ module GF.Command.TreeOperations (
|
||||
) where
|
||||
|
||||
import PGF
|
||||
import PGF.Data
|
||||
import PGF.Internal(Expr(..),unAppForm)
|
||||
import Data.List
|
||||
|
||||
type TreeOp = [Expr] -> [Expr]
|
||||
|
||||
@@ -34,7 +34,7 @@ import Data.List(nub)
|
||||
import Data.Time(UTCTime)
|
||||
import Text.PrettyPrint
|
||||
|
||||
import PGF.Optimize
|
||||
import PGF.Internal(optimizePGF)
|
||||
import PGF
|
||||
|
||||
-- | Compiles a number of source files and builds a 'PGF' structure for them.
|
||||
|
||||
@@ -4,9 +4,7 @@ import GF.Grammar.CFG
|
||||
import GF.Infra.UseIO
|
||||
|
||||
import PGF
|
||||
import PGF.Data
|
||||
import PGF.Macros
|
||||
import PGF.Optimize
|
||||
import PGF.Internal
|
||||
|
||||
import qualified Data.Set as Set
|
||||
import qualified Data.Map as Map
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module GF.Compile.Compute.Value where
|
||||
import GF.Grammar.Grammar(Label,Type,MetaId,Patt,QIdent)
|
||||
import PGF.Data(BindType)
|
||||
import PGF.Internal(BindType)
|
||||
import GF.Infra.Ident(Ident)
|
||||
import Text.Show.Functions()
|
||||
import Data.Ix(Ix)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module GF.Compile.Export where
|
||||
|
||||
import PGF
|
||||
import PGF.Printer(ppPGF)
|
||||
import PGF.Internal(ppPGF)
|
||||
import GF.Compile.PGFtoHaskell
|
||||
import GF.Compile.PGFtoProlog
|
||||
import GF.Compile.PGFtoLProlog
|
||||
|
||||
@@ -2,13 +2,13 @@ module GF.Compile.GenerateBC(generateByteCode) where
|
||||
|
||||
import GF.Grammar
|
||||
import GF.Compile.Instructions
|
||||
import PGF.Data
|
||||
import PGF.Internal(Binary(..),encode,BCAddr)
|
||||
|
||||
import Data.Maybe
|
||||
import qualified Data.IntMap as IntMap
|
||||
import qualified Data.ByteString as BSS
|
||||
import qualified Data.ByteString.Lazy as BS
|
||||
import Data.Binary
|
||||
import PGF.Internal()
|
||||
|
||||
generateByteCode :: [(QIdent,Info)] -> ([(QIdent,Info,BCAddr)], BSS.ByteString)
|
||||
generateByteCode = runGenM . mapM genFun
|
||||
|
||||
@@ -14,7 +14,7 @@ module GF.Compile.GeneratePMCFG
|
||||
) where
|
||||
|
||||
--import PGF.CId
|
||||
import PGF.Data(CncCat(..),Symbol(..),fidVar)
|
||||
import PGF.Internal as PGF(CncCat(..),Symbol(..),fidVar)
|
||||
|
||||
import GF.Infra.Option
|
||||
import GF.Grammar hiding (Env, mkRecord, mkTable)
|
||||
@@ -194,13 +194,12 @@ unfactor t = CM (\gr c -> c (unfac gr t))
|
||||
Vr y | y == x -> u
|
||||
_ -> composSafeOp (restore x u) t
|
||||
|
||||
pgfCncCat :: SourceGrammar -> Type -> Int -> PGF.Data.CncCat
|
||||
pgfCncCat :: SourceGrammar -> Type -> Int -> CncCat
|
||||
pgfCncCat gr lincat index =
|
||||
let ((_,size),schema) = computeCatRange gr lincat
|
||||
in PGF.Data.CncCat index
|
||||
(index+size-1)
|
||||
(mkArray (map (renderStyle style{mode=OneLineMode} . ppPath)
|
||||
(getStrPaths schema)))
|
||||
in PGF.CncCat index (index+size-1)
|
||||
(mkArray (map (renderStyle style{mode=OneLineMode} . ppPath)
|
||||
(getStrPaths schema)))
|
||||
where
|
||||
getStrPaths :: Schema Identity s c -> [Path]
|
||||
getStrPaths = collect CNil []
|
||||
|
||||
@@ -6,11 +6,11 @@ import GF.Compile.GeneratePMCFG
|
||||
import GF.Compile.GenerateBC
|
||||
|
||||
import PGF(CId,mkCId,utf8CId)
|
||||
import PGF.Data(fidInt,fidFloat,fidString,fidVar)
|
||||
import PGF.Optimize(updateProductionIndices)
|
||||
import PGF.Internal(fidInt,fidFloat,fidString,fidVar)
|
||||
import PGF.Internal(updateProductionIndices)
|
||||
--import qualified PGF.Macros as CM
|
||||
import qualified PGF.Data as C
|
||||
import qualified PGF.Data as D
|
||||
import qualified PGF.Internal as C
|
||||
import qualified PGF.Internal as D
|
||||
import GF.Grammar.Predef
|
||||
--import GF.Grammar.Printer
|
||||
import GF.Grammar.Grammar
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
module GF.Compile.Instructions where
|
||||
|
||||
--import Data.IORef
|
||||
import Data.Binary
|
||||
import Data.Binary.Put
|
||||
import Data.Binary.Get
|
||||
import Data.Binary.IEEE754
|
||||
import PGF.Internal -- Binary
|
||||
import PGF(CId)
|
||||
--import PGF.CId
|
||||
--import PGF.Binary
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
module GF.Compile.PGFtoHaskell (grammar2haskell) where
|
||||
|
||||
import PGF(showCId)
|
||||
import PGF.Data
|
||||
import PGF.Macros
|
||||
import PGF.Internal
|
||||
|
||||
import GF.Data.Operations
|
||||
import GF.Infra.Option
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
module GF.Compile.PGFtoJS (pgf2js) where
|
||||
|
||||
import PGF(showCId)
|
||||
import PGF.Data hiding (mkStr)
|
||||
import qualified PGF.Macros as M
|
||||
import PGF(CId,showCId)
|
||||
import PGF.Internal as M
|
||||
import qualified GF.JavaScript.AbsJS as JS
|
||||
import qualified GF.JavaScript.PrintJS as JS
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module GF.Compile.PGFtoLProlog(grammar2lambdaprolog_mod, grammar2lambdaprolog_sig) where
|
||||
|
||||
import PGF(mkCId,ppCId,showCId,wildCId)
|
||||
import PGF.Data hiding (ppExpr, ppType, ppHypo)
|
||||
import PGF.Internal hiding (ppExpr,ppType,ppHypo,ppCat,ppFun)
|
||||
--import PGF.Macros
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
module GF.Compile.PGFtoProlog (grammar2prolog) where
|
||||
|
||||
import PGF(mkCId,wildCId,showCId)
|
||||
import PGF.Data
|
||||
import PGF.Internal
|
||||
--import PGF.Macros
|
||||
|
||||
import GF.Data.Operations
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
module GF.Compile.PGFtoPython (pgf2python) where
|
||||
|
||||
import PGF(showCId)
|
||||
import PGF.Data
|
||||
import qualified PGF.Macros as M
|
||||
import PGF.Internal as M
|
||||
|
||||
import GF.Data.Operations
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ module GF.Compile.ToAPI
|
||||
(stringToAPI,exprToAPI)
|
||||
where
|
||||
|
||||
import PGF.Data
|
||||
import PGF.Internal
|
||||
import PGF(showCId)
|
||||
import Data.Maybe
|
||||
--import System.IO
|
||||
|
||||
@@ -13,7 +13,7 @@ import Prelude hiding (catch)
|
||||
import Control.Exception(catch,ErrorCall(..),throwIO)
|
||||
|
||||
--import Data.Char
|
||||
import Data.Binary
|
||||
import PGF.Internal(Binary(..),Word8,putWord8,getWord8,encodeFile,decodeFile)
|
||||
--import Control.Monad
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.ByteString.Char8 as BS
|
||||
@@ -24,7 +24,7 @@ import GF.Infra.Option
|
||||
import GF.Grammar.Grammar
|
||||
|
||||
import PGF() -- Binary instances
|
||||
import PGF.Data(Literal(..))
|
||||
import PGF.Internal(Literal(..))
|
||||
|
||||
-- Please change this every time when the GFO format is changed
|
||||
gfoVersion = "GF03"
|
||||
|
||||
@@ -66,7 +66,7 @@ import GF.Infra.Option ---
|
||||
|
||||
import GF.Data.Operations
|
||||
|
||||
import PGF.Data (FId, FunId, SeqId, LIndex, Sequence, BindType(..))
|
||||
import PGF.Internal (FId, FunId, SeqId, LIndex, Sequence, BindType(..))
|
||||
|
||||
--import Data.List
|
||||
import Data.Array.IArray
|
||||
|
||||
@@ -29,8 +29,7 @@ import GF.Infra.Option
|
||||
import GF.Grammar.Values
|
||||
import GF.Grammar.Grammar
|
||||
|
||||
import PGF.Data (ppMeta, ppLit)
|
||||
import PGF.Printer (ppFId, ppFunId, ppSeqId, ppSeq)
|
||||
import PGF.Internal (ppMeta, ppLit, ppFId, ppFunId, ppSeqId, ppSeq)
|
||||
|
||||
import Text.PrettyPrint
|
||||
import Data.Maybe (isNothing)
|
||||
|
||||
@@ -30,7 +30,7 @@ import qualified Data.ByteString.Char8 as BS(append,isPrefixOf)
|
||||
-- Limit use of BS functions to the ones that work correctly on
|
||||
-- UTF-8-encoded bytestrings!
|
||||
import Data.Char(isDigit)
|
||||
import Data.Binary(Binary(..))
|
||||
import PGF.Internal(Binary(..))
|
||||
import Text.PrettyPrint(Doc,text)
|
||||
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ import GF.Data.Operations(Err,ErrorMonad(..),liftErr)
|
||||
import Data.Set (Set)
|
||||
import qualified Data.Set as Set
|
||||
|
||||
import PGF.Data(Literal(..))
|
||||
import PGF.Internal(Literal(..))
|
||||
|
||||
usageHeader :: String
|
||||
usageHeader = unlines
|
||||
|
||||
@@ -14,8 +14,7 @@ import qualified Data.Map as Map
|
||||
import Data.Set (Set)
|
||||
import qualified Data.Set as Set
|
||||
|
||||
--import PGF.CId
|
||||
import PGF.Data
|
||||
import PGF.Internal
|
||||
import GF.Data.Utilities
|
||||
import GF.Grammar.CFG
|
||||
--import GF.Speech.PGFToCFG
|
||||
|
||||
@@ -18,8 +18,7 @@ import GF.Grammar.CFG
|
||||
import GF.Speech.RegExp
|
||||
import GF.Speech.SISR
|
||||
import GF.Speech.SRG
|
||||
--import PGF.CId
|
||||
import PGF.Data
|
||||
import PGF
|
||||
|
||||
import Data.Char
|
||||
import Data.List
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
module GF.Speech.PGFToCFG (bnfPrinter, pgfToCFG) where
|
||||
|
||||
import PGF(showCId)
|
||||
import PGF.Data as PGF
|
||||
import PGF.Macros
|
||||
import PGF.Internal as PGF
|
||||
--import GF.Infra.Ident
|
||||
import GF.Grammar.CFG hiding (Symbol)
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@ module GF.Speech.VoiceXML (grammar2vxml) where
|
||||
import GF.Data.XML
|
||||
--import GF.Infra.Ident
|
||||
import PGF
|
||||
import PGF.Data
|
||||
import PGF.Macros
|
||||
import PGF.Internal
|
||||
|
||||
--import Control.Monad (liftM)
|
||||
import Data.List (intersperse) -- isPrefixOf, find
|
||||
|
||||
@@ -2,10 +2,8 @@ module GFC (mainGFC, writePGF) where
|
||||
-- module Main where
|
||||
|
||||
import PGF
|
||||
--import PGF.CId
|
||||
import PGF.Data
|
||||
import PGF.Optimize
|
||||
import PGF.Binary(putSplitAbs)
|
||||
import PGF.Internal(PGF(..),code,funs,cats,optimizePGF,unionPGF)
|
||||
import PGF.Internal(putSplitAbs)
|
||||
import GF.Compile
|
||||
import GF.Compile.Export
|
||||
import GF.Compile.CFGtoPGF
|
||||
@@ -19,8 +17,7 @@ import GF.Data.ErrM
|
||||
import GF.System.Directory
|
||||
|
||||
import Data.Maybe
|
||||
import Data.Binary(encode,encodeFile)
|
||||
import Data.Binary.Put(runPut)
|
||||
import PGF.Internal(encode,encodeFile,runPut)
|
||||
import qualified Data.Map as Map
|
||||
import qualified Data.Set as Set
|
||||
import qualified Data.ByteString as BSS
|
||||
|
||||
@@ -29,8 +29,7 @@ import qualified System.Console.Haskeline as Haskeline
|
||||
--import GF.Compile.Coding(codeTerm)
|
||||
|
||||
import PGF
|
||||
import PGF.Data
|
||||
import PGF.Macros
|
||||
import PGF.Internal(emptyPGF,abstract,funs,lookStartCat)
|
||||
|
||||
import Data.Char
|
||||
import Data.List(nub,isPrefixOf,isInfixOf,partition)
|
||||
|
||||
@@ -17,7 +17,7 @@ import GF.Grammar.Printer(ppParams,ppTerm,getAbs,TermPrintQual(..))
|
||||
import GF.Grammar.Parser(runP,pModDef)
|
||||
import GF.Grammar.Lexer(Posn(..))
|
||||
import GF.Data.ErrM
|
||||
import PGF.Data(Literal(LStr))
|
||||
import PGF.Internal(Literal(LStr))
|
||||
|
||||
import SimpleEditor.Syntax as S
|
||||
import SimpleEditor.JSON
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable #-}
|
||||
-------------------------------------------------
|
||||
-- |
|
||||
-- Maintainer : Krasimir Angelov
|
||||
-- Stability : stable
|
||||
-- Portability : portable
|
||||
--
|
||||
-- This is the Haskell binding to the C run-time system for
|
||||
-- loading and interpreting grammars compiled in Portable Grammar Format (PGF).
|
||||
-------------------------------------------------
|
||||
#include <pgf/pgf.h>
|
||||
#include <gu/enum.h>
|
||||
#include <gu/exn.h>
|
||||
|
||||
18
src/runtime/haskell/PGF/Internal.hs
Normal file
18
src/runtime/haskell/PGF/Internal.hs
Normal file
@@ -0,0 +1,18 @@
|
||||
{-# OPTIONS_HADDOCK hide #-}
|
||||
-------------------------------------------------
|
||||
-- |
|
||||
-- Stability : unstable
|
||||
--
|
||||
-------------------------------------------------
|
||||
module PGF.Internal(module Internal) where
|
||||
import PGF.Binary as Internal
|
||||
import PGF.Data as Internal
|
||||
import PGF.Macros as Internal
|
||||
import PGF.Optimize as Internal
|
||||
import PGF.Printer as Internal
|
||||
import PGF.Utilities as Internal
|
||||
|
||||
import Data.Binary as Internal
|
||||
import Data.Binary.Get as Internal
|
||||
import Data.Binary.IEEE754 as Internal
|
||||
import Data.Binary.Put as Internal
|
||||
@@ -3,10 +3,10 @@ module PGF.Utilities where
|
||||
import Data.Set(empty,member,insert)
|
||||
|
||||
|
||||
-- | Like 'nub', but O(n log n) instead of O(n^2), since it uses a set to lookup previous things.
|
||||
-- | Like 'Data.List.nub', but O(n log n) instead of O(n^2), since it uses a set to lookup previous things.
|
||||
-- The result list is stable (the elements are returned in the order they occur), and lazy.
|
||||
-- Requires that the list elements can be compared by Ord.
|
||||
-- Code ruthlessly taken from http://hpaste.org/54411
|
||||
-- Code ruthlessly taken from <http://hpaste.org/54411>
|
||||
nub' :: Ord a => [a] -> [a]
|
||||
nub' = loop empty
|
||||
where loop _ [] = []
|
||||
|
||||
Reference in New Issue
Block a user