1
0
forked from GitHub/gf-core

More haddock documentation improvements

This commit is contained in:
hallgren
2014-10-16 14:03:57 +00:00
parent c0ebbc4edf
commit c924491289
16 changed files with 92 additions and 56 deletions

View File

@@ -35,6 +35,7 @@ import GF.System.Directory(removeFile,getCurrentDirectory)
import System.FilePath(makeRelative) import System.FilePath(makeRelative)
--getSourceModule :: Options -> FilePath -> IOE SourceModule --getSourceModule :: Options -> FilePath -> IOE SourceModule
-- | Read a source file and parse it (after applying preprocessors specified in the options)
getSourceModule opts file0 = getSourceModule opts file0 =
--errIn file0 $ --errIn file0 $
do tmp <- liftIO $ foldM runPreprocessor (Source file0) (flag optPreprocessors opts) do tmp <- liftIO $ foldM runPreprocessor (Source file0) (flag optPreprocessors opts)

View File

@@ -1,5 +1,5 @@
-- | Parallel grammar compilation -- | Parallel grammar compilation
module GF.CompileInParallel(batchCompile) where module GF.CompileInParallel(parallelBatchCompile) where
import Prelude hiding (catch) import Prelude hiding (catch)
import Control.Monad(join,ap,when,unless) import Control.Monad(join,ap,when,unless)
import Control.Applicative import Control.Applicative
@@ -19,8 +19,14 @@ import GF.Infra.Ident(identS)
import GF.Text.Pretty import GF.Text.Pretty
import qualified Data.ByteString.Lazy as BS import qualified Data.ByteString.Lazy as BS
-- | Compile the given grammar files and everything they depend on -- | Compile the given grammar files and everything they depend on.
batchCompile jobs opts rootfiles0 = -- This function compiles modules in parallel.
-- It keeps modules compiled in /present/ and /alltenses/ mode apart,
-- storing the @.gfo@ files in separate subdirectories to avoid creating
-- the broken PGF files that can result from mixing different modes in the
-- same concrete syntax.
parallelBatchCompile jobs opts rootfiles0 =
do rootfiles <- mapM canonical rootfiles0 do rootfiles <- mapM canonical rootfiles0
lib_dir <- canonical =<< getLibraryDirectory opts lib_dir <- canonical =<< getLibraryDirectory opts
filepaths <- mapM (getPathFromFile lib_dir opts) rootfiles filepaths <- mapM (getPathFromFile lib_dir opts) rootfiles

View File

@@ -1,4 +1,5 @@
module GF.CompileOne(OneOutput,CompiledModule, module GF.CompileOne(-- ** Compiling a single module
OneOutput,CompiledModule,
compileOne,reuseGFO,useTheSource compileOne,reuseGFO,useTheSource
--, CompileSource, compileSourceModule --, CompileSource, compileSourceModule
) where ) where
@@ -18,9 +19,9 @@ import GF.Grammar.Printer(ppModule,TermPrintQual(..))
import GF.Grammar.Binary(decodeModule,encodeModule) import GF.Grammar.Binary(decodeModule,encodeModule)
import GF.Infra.Option import GF.Infra.Option
import GF.Infra.UseIO(FullPath,IOE,isGFO,gf2gfo,Output(..),putPointE) import GF.Infra.UseIO(FullPath,IOE,isGFO,gf2gfo,MonadIO(..),Output(..),putPointE)
import GF.Infra.CheckM(runCheck') import GF.Infra.CheckM(runCheck')
import GF.Data.Operations(liftErr,(+++)) import GF.Data.Operations(ErrorMonad,liftErr,(+++))
import GF.System.Directory(doesFileExist,getCurrentDirectory,renameFile) import GF.System.Directory(doesFileExist,getCurrentDirectory,renameFile)
import qualified Data.Map as Map import qualified Data.Map as Map
@@ -30,9 +31,13 @@ import Control.Monad((<=<))
type OneOutput = (Maybe FullPath,CompiledModule) type OneOutput = (Maybe FullPath,CompiledModule)
type CompiledModule = SourceModule type CompiledModule = SourceModule
--compileOne :: Options -> SourceGrammar -> FullPath -> IOE OneOutput compileOne, reuseGFO, useTheSource ::
(Output m,ErrorMonad m,MonadIO m) =>
Options -> SourceGrammar -> FullPath -> m OneOutput
-- | Compile a given source file (or just load a .gfo file), -- | Compile a given source file (or just load a .gfo file),
-- given a 'SourceGrammar' containing everything it depends on. -- given a 'SourceGrammar' containing everything it depends on.
-- Calls 'reuseGFO' or 'useTheSource'.
compileOne opts srcgr file = compileOne opts srcgr file =
if isGFO file if isGFO file
then reuseGFO opts srcgr file then reuseGFO opts srcgr file
@@ -40,7 +45,7 @@ compileOne opts srcgr file =
if b1 then useTheSource opts srcgr file if b1 then useTheSource opts srcgr file
else reuseGFO opts srcgr (gf2gfo opts file) else reuseGFO opts srcgr (gf2gfo opts file)
-- | For compiled gf, read the file and update environment. -- | Read a compiled GF module.
-- Also undo common subexp optimization, to enable normal computations. -- Also undo common subexp optimization, to enable normal computations.
reuseGFO opts srcgr file = reuseGFO opts srcgr file =
do sm00 <- putPointE Verbose opts ("+ reading" +++ file) $ do sm00 <- putPointE Verbose opts ("+ reading" +++ file) $
@@ -62,7 +67,9 @@ reuseGFO opts srcgr file =
return (Just file,sm) return (Just file,sm)
--useTheSource :: Options -> SourceGrammar -> FullPath -> IOE OneOutput --useTheSource :: Options -> SourceGrammar -> FullPath -> IOE OneOutput
-- | For gf source, do full compilation and generate code. -- | Compile GF module from source. It both returns the result and
-- stores it in a @.gfo@ file
-- (or a tags file, if running with the @-tags@ option)
useTheSource opts srcgr file = useTheSource opts srcgr file =
do sm <- putpOpt ("- parsing" +++ file) do sm <- putpOpt ("- parsing" +++ file)
("- compiling" +++ file ++ "... ") ("- compiling" +++ file ++ "... ")

View File

@@ -4,7 +4,7 @@ import PGF
import PGF.Internal(concretes,optimizePGF,unionPGF) import PGF.Internal(concretes,optimizePGF,unionPGF)
import PGF.Internal(putSplitAbs,encodeFile,runPut) import PGF.Internal(putSplitAbs,encodeFile,runPut)
import GF.Compile as S(batchCompile,link,srcAbsName) import GF.Compile as S(batchCompile,link,srcAbsName)
import qualified GF.CompileInParallel as P(batchCompile) import GF.CompileInParallel as P(parallelBatchCompile)
import GF.Compile.Export import GF.Compile.Export
import GF.Compile.CFGtoPGF import GF.Compile.CFGtoPGF
import GF.Compile.GetGrammar import GF.Compile.GetGrammar
@@ -56,7 +56,7 @@ compileSourceFiles opts fs =
writePGF opts pgf writePGF opts pgf
writeOutputs opts pgf writeOutputs opts pgf
where where
batchCompile = maybe batchCompile' P.batchCompile (flag optJobs opts) batchCompile = maybe batchCompile' parallelBatchCompile (flag optJobs opts)
batchCompile' opts fs = do (cnc,t,gr) <- S.batchCompile opts fs batchCompile' opts fs = do (cnc,t,gr) <- S.batchCompile opts fs
return (t,[(cnc,gr)]) return (t,[(cnc,gr)])

View File

@@ -14,19 +14,19 @@
-- Copyright (c) Aarne Ranta 1998-2000, under GNU General Public License (see GPL) -- Copyright (c) Aarne Ranta 1998-2000, under GNU General Public License (see GPL)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module GF.Data.Operations (-- * misc functions module GF.Data.Operations (-- ** Misc functions
ifNull, ifNull,
-- * the Error monad -- ** The Error monad
Err(..), err, maybeErr, testErr, errVal, errIn, Err(..), err, maybeErr, testErr, errVal, errIn,
lookupErr, lookupErr,
mapPairListM, mapPairsM, pairM, mapPairListM, mapPairsM, pairM,
singleton, --mapsErr, mapsErrTree, singleton, --mapsErr, mapsErrTree,
-- ** checking -- ** Checking
checkUnique, unifyMaybeBy, unifyMaybe, checkUnique, unifyMaybeBy, unifyMaybe,
-- * binary search trees; now with FiniteMap -- ** Binary search trees; now with FiniteMap
BinTree, emptyBinTree, isInBinTree, justLookupTree, BinTree, emptyBinTree, isInBinTree, justLookupTree,
lookupTree, --lookupTreeMany, lookupTree, --lookupTreeMany,
lookupTreeManyAll, updateTree, lookupTreeManyAll, updateTree,
@@ -36,28 +36,28 @@ module GF.Data.Operations (-- * misc functions
tree2list, tree2list,
-- * printing -- ** Printing
indent, (+++), (++-), (++++), (+++++), indent, (+++), (++-), (++++), (+++++),
prUpper, prReplicate, prTList, prQuotedString, prParenth, prCurly, prUpper, prReplicate, prTList, prQuotedString, prParenth, prCurly,
prBracket, prArgList, prSemicList, prCurlyList, restoreEscapes, prBracket, prArgList, prSemicList, prCurlyList, restoreEscapes,
numberedParagraphs, prConjList, prIfEmpty, wrapLines, numberedParagraphs, prConjList, prIfEmpty, wrapLines,
-- * extra -- ** Extra
combinations, combinations,
-- * topological sorting with test of cyclicity -- ** Topological sorting with test of cyclicity
topoTest, topoTest2, topoTest, topoTest2,
-- * the generic fix point iterator -- ** The generic fix point iterator
iterFix, iterFix,
-- * chop into separator-separated parts -- ** Chop into separator-separated parts
chunks, readIntArg, chunks, readIntArg,
-- * state monad with error; from Agda 6\/11\/2001 -- ** State monad with error; from Agda 6\/11\/2001
STM(..), appSTM, stm, stmr, readSTM, updateSTM, writeSTM, done, STM(..), appSTM, stm, stmr, readSTM, updateSTM, writeSTM, done,
-- * error monad class -- ** Error monad class
ErrorMonad(..), checkAgain, checks, allChecks, doUntil, ErrorMonad(..), checkAgain, checks, allChecks, doUntil,
liftErr liftErr

View File

@@ -12,18 +12,18 @@
-- (Description of the module) -- (Description of the module)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module GF.Grammar module GF.Grammar
( module GF.Infra.Ident, ( module GF.Grammar.Grammar,
module GF.Grammar.Grammar,
module GF.Grammar.Values, module GF.Grammar.Values,
module GF.Grammar.Macros, module GF.Grammar.Macros,
module GF.Grammar.MMacros, module GF.Grammar.MMacros,
module GF.Grammar.Printer module GF.Grammar.Printer,
module GF.Infra.Ident
) where ) where
import GF.Infra.Ident
import GF.Grammar.Grammar import GF.Grammar.Grammar
import GF.Grammar.Values import GF.Grammar.Values
import GF.Grammar.Macros import GF.Grammar.Macros
import GF.Grammar.MMacros import GF.Grammar.MMacros
import GF.Grammar.Printer import GF.Grammar.Printer
import GF.Infra.Ident

View File

@@ -15,6 +15,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module GF.Grammar.Grammar ( module GF.Grammar.Grammar (
-- ** Grammar modules
SourceGrammar, SourceModInfo(..), SourceModule, ModuleType(..), SourceGrammar, SourceModInfo(..), SourceModule, ModuleType(..),
emptySourceGrammar, mGrammar, modules, prependModule, moduleMap, emptySourceGrammar, mGrammar, modules, prependModule, moduleMap,
@@ -32,9 +33,8 @@ module GF.Grammar.Grammar (
abstractOfConcrete, abstractOfConcrete,
ModuleStatus(..), ModuleStatus(..),
PMCFG(..), Production(..), FId, FunId, SeqId, LIndex, Sequence, -- ** Judgements and terms
Info(..), Info(..),
Location(..), L(..), unLoc, noLoc, ppLocation, ppL, Location(..), L(..), unLoc, noLoc, ppLocation, ppL,
Type, Type,
@@ -58,7 +58,10 @@ module GF.Grammar.Grammar (
Altern, Altern,
Substitution, Substitution,
varLabel, tupleLabel, linLabel, theLinLabel, varLabel, tupleLabel, linLabel, theLinLabel,
ident2label, label2ident ident2label, label2ident,
-- ** PMCFG
PMCFG(..), Production(..), FId, FunId, SeqId, LIndex, Sequence
) where ) where
import GF.Infra.Ident import GF.Infra.Ident

View File

@@ -28,6 +28,8 @@ import GF.Grammar.Macros
import Control.Monad import Control.Monad
import GF.Text.Pretty import GF.Text.Pretty
-- ** Some more abstractions on grammars, esp. for Edit
{- {-
nodeTree :: Tree -> TrNode nodeTree :: Tree -> TrNode
argsTree :: Tree -> [Tree] argsTree :: Tree -> [Tree]
@@ -151,7 +153,7 @@ substTerm ss g c = case c of
metaSubstExp :: MetaSubst -> [(MetaId,Exp)] metaSubstExp :: MetaSubst -> [(MetaId,Exp)]
metaSubstExp msubst = [(m, errVal (meta2exp m) (val2expSafe v)) | (m,v) <- msubst] metaSubstExp msubst = [(m, errVal (meta2exp m) (val2expSafe v)) | (m,v) <- msubst]
-- * belong here rather than to computation -- ** belong here rather than to computation
substitute :: [Var] -> Substitution -> Exp -> Err Exp substitute :: [Var] -> Substitution -> Exp -> Err Exp
substitute v s = return . substTerm v s substitute v s = return . substTerm v s

View File

@@ -33,6 +33,8 @@ import Control.Monad (liftM, liftM2, liftM3)
import Data.List (sortBy,nub) import Data.List (sortBy,nub)
import GF.Text.Pretty import GF.Text.Pretty
-- ** Macros for constructing and analysing source code terms.
typeForm :: Type -> (Context, Cat, [Term]) typeForm :: Type -> (Context, Cat, [Term])
typeForm t = typeForm t =
case t of case t of

View File

@@ -8,7 +8,8 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module GF.Grammar.Printer module GF.Grammar.Printer
( TermPrintQual(..) ( -- ** Pretty printing
TermPrintQual(..)
, ppModule , ppModule
, ppJudgement , ppJudgement
, ppParams , ppParams

View File

@@ -12,12 +12,12 @@
-- (Description of the module) -- (Description of the module)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module GF.Grammar.Values (-- * values used in TC type checking module GF.Grammar.Values (-- ** Values used in TC type checking
Exp, Val(..), Env, Exp, Val(..), Env,
-- * annotated tree used in editing -- ** Annotated tree used in editing
--Z Tree, TrNode(..), Atom(..), --Z Tree, TrNode(..), Atom(..),
Binds, Constraints, MetaSubst, Binds, Constraints, MetaSubst,
-- * for TC -- ** For TC
valAbsInt, valAbsFloat, valAbsString, vType, valAbsInt, valAbsFloat, valAbsString, vType,
isPredefCat, isPredefCat,
eType, eType,

View File

@@ -12,15 +12,15 @@
-- (Description of the module) -- (Description of the module)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module GF.Infra.Ident (-- * Identifiers module GF.Infra.Ident (-- ** Identifiers
Ident, ident2utf8, showIdent, prefixIdent, Ident, ident2utf8, showIdent, prefixIdent,
identS, identC, identV, identA, identAV, identW, identS, identC, identV, identA, identAV, identW,
argIdent, isArgIdent, getArgIndex, argIdent, isArgIdent, getArgIndex,
varStr, varX, isWildIdent, varIndex, varStr, varX, isWildIdent, varIndex,
-- * Raw Identifiers -- ** Raw Identifiers
RawIdent, rawIdentS, rawIdentC, ident2raw, prefixRawIdent, RawIdent, rawIdentS, rawIdentC, ident2raw, prefixRawIdent,
isPrefixOf, showRawIdent{-, isPrefixOf, showRawIdent{-,
-- * Refreshing identifiers -- ** Refreshing identifiers
IdState, initIdStateN, initIdState, IdState, initIdStateN, initIdState,
lookVar, refVar, refVarPlus-} lookVar, refVar, refVarPlus-}
) where ) where

View File

@@ -1,6 +1,6 @@
module GF.Infra.Option module GF.Infra.Option
( (
-- * Option types -- ** Option types
Options, Options,
Flags(..), Flags(..),
Mode(..), Phase(..), Verbosity(..), Mode(..), Phase(..), Verbosity(..),
@@ -8,21 +8,21 @@ module GF.Infra.Option
SISRFormat(..), Optimization(..), CFGTransform(..), HaskellOption(..), SISRFormat(..), Optimization(..), CFGTransform(..), HaskellOption(..),
Dump(..), Pass(..), Recomp(..), Dump(..), Pass(..), Recomp(..),
outputFormatsExpl, outputFormatsExpl,
-- * Option parsing -- ** Option parsing
parseOptions, parseModuleOptions, fixRelativeLibPaths, parseOptions, parseModuleOptions, fixRelativeLibPaths,
-- * Option pretty-printing -- ** Option pretty-printing
optionsGFO, optionsGFO,
optionsPGF, optionsPGF,
-- * Option manipulation -- ** Option manipulation
addOptions, concatOptions, noOptions, addOptions, concatOptions, noOptions,
modifyFlags, modifyFlags,
helpMessage, helpMessage,
-- * Checking specific options -- ** Checking specific options
flag, cfgTransform, haskellOption, readOutputFormat, flag, cfgTransform, haskellOption, readOutputFormat,
isLexicalCat, isLiteralCat, renameEncoding, getEncoding, defaultEncoding, isLexicalCat, isLiteralCat, renameEncoding, getEncoding, defaultEncoding,
-- * Setting specific options -- ** Setting specific options
setOptimization, setCFGTransform, setOptimization, setCFGTransform,
-- * Convenience methods for checking options -- ** Convenience methods for checking options
verbAtLeast, dump verbAtLeast, dump
) where ) where

View File

@@ -12,7 +12,9 @@
-- (Description of the module) -- (Description of the module)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module GF.Infra.UseIO(module GF.Infra.UseIO,MonadIO(..),liftErr) where module GF.Infra.UseIO(module GF.Infra.UseIO,liftErr,
-- ** Reused
MonadIO(..),liftErr) where
import Prelude hiding (catch) import Prelude hiding (catch)
@@ -38,6 +40,8 @@ import Control.Exception(evaluate)
--putIfVerb :: MonadIO io => Options -> String -> io () --putIfVerb :: MonadIO io => Options -> String -> io ()
putIfVerb opts msg = when (verbAtLeast opts Verbose) $ putStrLnE msg putIfVerb opts msg = when (verbAtLeast opts Verbose) $ putStrLnE msg
-- ** GF files path and library path manipulation
type FileName = String type FileName = String
type InitPath = String -- ^ the directory portion of a pathname type InitPath = String -- ^ the directory portion of a pathname
type FullPath = String type FullPath = String
@@ -119,7 +123,7 @@ splitInModuleSearchPath s = case break isPathSep s of
-- --
-- * IO monad with error; adapted from state monad -- ** IO monad with error; adapted from state monad
newtype IOE a = IOE { appIOE :: IO (Err a) } newtype IOE a = IOE { appIOE :: IO (Err a) }
@@ -165,6 +169,8 @@ die :: String -> IO a
die s = do hPutStrLn stderr s die s = do hPutStrLn stderr s
exitFailure exitFailure
-- ** Diagnostic output
class Monad m => Output m where class Monad m => Output m where
ePutStr, ePutStrLn, putStrE, putStrLnE :: String -> m () ePutStr, ePutStrLn, putStrE, putStrLnE :: String -> m ()
@@ -195,13 +201,21 @@ putPointE v opts msg act = do
return a return a
-- | Because GHC adds the confusing text "user error" for failures caused by
-- calls to fail.
ioErrorText e = if isUserError e
then ioeGetErrorString e
else show e
-- ** Timing
timeIt act = timeIt act =
do t1 <- liftIO $ getCPUTime do t1 <- liftIO $ getCPUTime
a <- liftIO . evaluate =<< act a <- liftIO . evaluate =<< act
t2 <- liftIO $ getCPUTime t2 <- liftIO $ getCPUTime
return (t2-t1,a) return (t2-t1,a)
-- * File IO -- ** File IO
writeUTF8File :: FilePath -> String -> IO () writeUTF8File :: FilePath -> String -> IO ()
writeUTF8File fpath content = writeUTF8File fpath content =
@@ -210,9 +224,3 @@ writeUTF8File fpath content =
readBinaryFile path = hGetContents =<< openBinaryFile path ReadMode readBinaryFile path = hGetContents =<< openBinaryFile path ReadMode
writeBinaryFile path s = withBinaryFile path WriteMode (flip hPutStr s) writeBinaryFile path s = withBinaryFile path WriteMode (flip hPutStr s)
-- | Because GHC adds the confusing text "user error" for failures caused by
-- calls to fail.
ioErrorText e = if isUserError e
then ioeGetErrorString e
else show e

View File

@@ -53,11 +53,13 @@ import GF.Infra.BuildInfo(buildInfo)
import Data.Version(showVersion) import Data.Version(showVersion)
import Paths_gf(version) import Paths_gf(version)
-- | Run the GF Shell in quiet mode
mainRunGFI :: Options -> [FilePath] -> IO () mainRunGFI :: Options -> [FilePath] -> IO ()
mainRunGFI opts files = shell (beQuiet opts) files mainRunGFI opts files = shell (beQuiet opts) files
beQuiet = addOptions (modifyFlags (\f -> f{optVerbosity=Quiet})) beQuiet = addOptions (modifyFlags (\f -> f{optVerbosity=Quiet}))
-- | Run the interactive GF Shell
mainGFI :: Options -> [FilePath] -> IO () mainGFI :: Options -> [FilePath] -> IO ()
mainGFI opts files = do mainGFI opts files = do
P.putStrLn welcome P.putStrLn welcome
@@ -66,6 +68,7 @@ mainGFI opts files = do
shell opts files = loop opts =<< runSIO (importInEnv emptyGFEnv opts files) shell opts files = loop opts =<< runSIO (importInEnv emptyGFEnv opts files)
#ifdef SERVER_MODE #ifdef SERVER_MODE
-- | Start GF Server
mainServerGFI opts0 port files = mainServerGFI opts0 port files =
server port root (execute1 opts) server port root (execute1 opts)
=<< runSIO (importInEnv emptyGFEnv opts files) =<< runSIO (importInEnv emptyGFEnv opts files)

View File

@@ -1,11 +1,14 @@
{-# LANGUAGE CPP #-} {-# LANGUAGE CPP #-}
module GF.System.Console(setConsoleEncoding,changeConsoleEncoding) where module GF.System.Console(
-- ** Changing which character encoding to use for console IO
setConsoleEncoding,changeConsoleEncoding) where
import System.IO import System.IO
#ifdef mingw32_HOST_OS #ifdef mingw32_HOST_OS
import System.Win32.Console import System.Win32.Console
import System.Win32.NLS import System.Win32.NLS
#endif #endif
-- | Set the console encoding (for Windows, has no effect on Unix-like systems)
setConsoleEncoding = setConsoleEncoding =
#ifdef mingw32_HOST_OS #ifdef mingw32_HOST_OS
do codepage <- getACP do codepage <- getACP