summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler/GF.hs12
-rw-r--r--src/compiler/GF/Compile.hs1
-rw-r--r--src/compiler/GF/Compile/Compute/ConcreteNew.hs2
-rw-r--r--src/compiler/GF/Compiler.hs37
-rw-r--r--src/compiler/GF/Interactive.hs5
5 files changed, 37 insertions, 20 deletions
diff --git a/src/compiler/GF.hs b/src/compiler/GF.hs
index bdb3e9b48..64c3184c6 100644
--- a/src/compiler/GF.hs
+++ b/src/compiler/GF.hs
@@ -1,8 +1,8 @@
module GF(
-- * Command line interface
module GF.Main,
- module GF.Compiler,
module GF.Interactive,
+ module GF.Compiler,
-- * Compiling GF grammars
module GF.Compile,
@@ -11,7 +11,10 @@ module GF(
-- * Abstract syntax, parsing and pretty printing
module GF.Compile.GetGrammar,
- module GF.Grammar,
+ module GF.Grammar.Grammar,
+ module GF.Grammar.Macros,
+ module GF.Grammar.Printer,
+ module GF.Infra.Ident,
-- * Supporting infrastructure and system utilities
module GF.Data.Operations,
@@ -28,7 +31,10 @@ import GF.CompileInParallel
import GF.CompileOne
import GF.Compile.GetGrammar
-import GF.Grammar
+import GF.Grammar.Grammar
+import GF.Grammar.Macros
+import GF.Grammar.Printer
+import GF.Infra.Ident
import GF.Data.Operations
import GF.Infra.Option
diff --git a/src/compiler/GF/Compile.hs b/src/compiler/GF/Compile.hs
index b52469cdb..fb37cd1fe 100644
--- a/src/compiler/GF/Compile.hs
+++ b/src/compiler/GF/Compile.hs
@@ -26,6 +26,7 @@ import PGF.Internal(optimizePGF)
import PGF(PGF,defaultProbabilities,setProbabilities,readProbabilitiesFromFile)
-- | Compiles a number of source files and builds a 'PGF' structure for them.
+-- This is a composition of 'batchCompile' and 'link'.
compileToPGF :: Options -> [FilePath] -> IOE PGF
compileToPGF opts fs = link opts =<< batchCompile opts fs
diff --git a/src/compiler/GF/Compile/Compute/ConcreteNew.hs b/src/compiler/GF/Compile/Compute/ConcreteNew.hs
index c4793c023..6bc653983 100644
--- a/src/compiler/GF/Compile/Compute/ConcreteNew.hs
+++ b/src/compiler/GF/Compile/Compute/ConcreteNew.hs
@@ -7,7 +7,7 @@ module GF.Compile.Compute.ConcreteNew
import GF.Grammar hiding (Env, VGen, VApp, VRecType)
import GF.Grammar.Lookup(lookupResDefLoc,allParamValues)
-import GF.Grammar.Predef(cPredef,cErrorType,cTok,cStr)
+import GF.Grammar.Predef(cPredef,cErrorType,cTok,cStr,isPredefCat)
import GF.Grammar.PatternMatch(matchPattern,measurePatt)
import GF.Grammar.Lockfield(lockLabel,isLockLabel,lockRecType) --unlockRecord
import GF.Compile.Compute.Value hiding (Error)
diff --git a/src/compiler/GF/Compiler.hs b/src/compiler/GF/Compiler.hs
index 407ef4e64..e607c7acc 100644
--- a/src/compiler/GF/Compiler.hs
+++ b/src/compiler/GF/Compiler.hs
@@ -1,4 +1,4 @@
-module GF.Compiler (mainGFC, writePGF) where
+module GF.Compiler (mainGFC, writePGF, linkGrammars) where
import PGF
import PGF.Internal(concretes,optimizePGF,unionPGF)
@@ -23,6 +23,8 @@ import qualified Data.ByteString.Lazy as BSL
import System.FilePath
import Control.Monad(unless,forM_)
+-- | Compile the given GF grammar files. The result is a number of @.gfo@ files
+-- and, depending on the options, a @.pgf@ file. (@gf -batch@, @gf -make@)
mainGFC :: Options -> [FilePath] -> IO ()
mainGFC opts fs = do
r <- appIOE (case () of
@@ -41,25 +43,29 @@ mainGFC opts fs = do
compileSourceFiles :: Options -> [FilePath] -> IOE ()
compileSourceFiles opts fs =
- do (t_src,~cnc_grs@(~(cnc,gr):_)) <- batchCompile opts fs
+ do output <- batchCompile opts fs
unless (flag optStopAfterPhase opts == Compile) $
- do let abs = showIdent (srcAbsName gr cnc)
- pgfFile = outputPath opts (grammarName' opts abs<.>"pgf")
- t_pgf <- if outputJustPGF opts
- then maybeIO $ getModificationTime pgfFile
- else return Nothing
- if t_pgf >= Just t_src
- then putIfVerb opts $ pgfFile ++ " is up-to-date."
- else do pgfs <- mapM (link opts)
- [(cnc,t_src,gr)|(cnc,gr)<-cnc_grs]
- let pgf = foldl1 unionPGF pgfs
- writePGF opts pgf
- writeOutputs opts pgf
+ linkGrammars opts output
where
batchCompile = maybe batchCompile' parallelBatchCompile (flag optJobs opts)
batchCompile' opts fs = do (cnc,t,gr) <- S.batchCompile opts fs
return (t,[(cnc,gr)])
+-- | Create a @.pgf@ file from the output of 'parallelBatchCompile'.
+linkGrammars opts (t_src,~cnc_grs@(~(cnc,gr):_)) =
+ do let abs = showIdent (srcAbsName gr cnc)
+ pgfFile = outputPath opts (grammarName' opts abs<.>"pgf")
+ t_pgf <- if outputJustPGF opts
+ then maybeIO $ getModificationTime pgfFile
+ else return Nothing
+ if t_pgf >= Just t_src
+ then putIfVerb opts $ pgfFile ++ " is up-to-date."
+ else do pgfs <- mapM (link opts)
+ [(cnc,t_src,gr)|(cnc,gr)<-cnc_grs]
+ let pgf = foldl1 unionPGF pgfs
+ writePGF opts pgf
+ writeOutputs opts pgf
+
compileCFFiles :: Options -> [FilePath] -> IOE ()
compileCFFiles opts fs = do
rules <- fmap concat $ mapM (getCFRules opts) fs
@@ -107,6 +113,9 @@ writeOutputs opts pgf = do
| fmt <- outputFormats opts,
(name,str) <- exportPGF opts fmt pgf]
+-- | Write the result of compiling a grammar (e.g. with 'compileToPGF' or
+-- 'link') to a @.pgf@ file.
+-- A split PGF file is output if the @-split-pgf@ option is used.
writePGF :: Options -> PGF -> IOE ()
writePGF opts pgf =
if flag optSplitPGF opts then writeSplitPGF else writeNormalPGF
diff --git a/src/compiler/GF/Interactive.hs b/src/compiler/GF/Interactive.hs
index 5944d04a7..18bee2e49 100644
--- a/src/compiler/GF/Interactive.hs
+++ b/src/compiler/GF/Interactive.hs
@@ -53,7 +53,7 @@ import GF.Infra.BuildInfo(buildInfo)
import Data.Version(showVersion)
import Paths_gf(version)
--- | Run the GF Shell in quiet mode
+-- | Run the GF Shell in quiet mode (@gf -run@).
mainRunGFI :: Options -> [FilePath] -> IO ()
mainRunGFI opts files = shell (beQuiet opts) files
@@ -68,7 +68,8 @@ mainGFI opts files = do
shell opts files = loop opts =<< runSIO (importInEnv emptyGFEnv opts files)
#ifdef SERVER_MODE
--- | Start GF Server
+-- | Run the GF Server (@gf -server@).
+-- The 'Int' argument is the port number for the HTTP service.
mainServerGFI opts0 port files =
server port root (execute1 opts)
=<< runSIO (importInEnv emptyGFEnv opts files)