This commit is contained in:
aarne
2004-04-01 09:51:32 +00:00
parent 8d828c46d5
commit cef421db7e
12 changed files with 64 additions and 24 deletions

View File

@@ -8,6 +8,7 @@ import Compile
import ShellState
import Modules
import ReadFiles (isOldFile)
import Option
import Operations
import UseIO
@@ -45,9 +46,12 @@ shellStateFromFiles opts st file = case fileSuffix file of
grts <- compileModule osb st file
ioeErr $ updateShellState opts st grts
_ -> do
let osb = if oElem showOld opts
then addOptions (options [beVerbose]) opts -- for old, no emit
else addOptions (options [beVerbose, emitCode]) opts -- for new,do
b <- ioeIO $ isOldFile file
let opts' = if b then (addOption showOld opts) else opts
let osb = if oElem showOld opts'
then addOptions (options [beVerbose]) opts' -- for old no emit
else addOptions (options [beVerbose, emitCode]) opts'
grts <- compileModule osb st file
ioeErr $ updateShellState opts st grts
ioeErr $ updateShellState opts' st grts
--- liftM (changeModTimes rts) $ grammar2shellState opts gr

View File

@@ -56,8 +56,9 @@ batchCompileOld f = compileOld defOpts f
compileModule :: Options -> ShellState -> FilePath ->
IOE (GFC.CanonGrammar, (SourceGrammar,[(FilePath,ModTime)]))
compileModule opts st0 file | oElem showOld opts ||
elem suff ["cf","ebnf"] = do
compileModule opts st0 file |
oElem showOld opts ||
elem suff ["cf","ebnf"] = do
let putp = putPointE opts
let path = [] ----
grammar1 <- if suff == "cf"

View File

@@ -210,6 +210,20 @@ greatestAbstract gr = case allAbstracts gr of
[] -> Nothing
a -> return $ last a
-- all resource modules
allResources :: G.SourceGrammar -> [Ident]
allResources gr = [i | (i,M.ModMod m) <- M.modules gr, M.mtype m == M.MTResource]
-- the last resource in dependency order
greatestResource :: G.SourceGrammar -> Maybe Ident
greatestResource gr = case allResources gr of
[] -> Nothing
a -> return $ last a
resourceOfShellState :: ShellState -> Maybe Ident
resourceOfShellState = greatestResource . srcModules
qualifTop :: StateGrammar -> G.QIdent -> G.QIdent
qualifTop gr (_,c) = (absId gr,c)

View File

@@ -182,6 +182,7 @@ withFun = aOpt "fun"
firstCat = aOpt "cat" -- used on command line
gStartCat = aOpt "startcat" -- used in grammar, to avoid clash w res word
useLanguage = aOpt "lang"
useResource = aOpt "res"
speechLanguage = aOpt "language"
useFont = aOpt "font"
grammarFormat = aOpt "format"

View File

@@ -6,7 +6,7 @@ module ReadFiles
--
getAllFiles,fixNewlines,ModName,getOptionsFromFile,
--
gfcFile,gfFile,gfrFile,isGFC,resModName) where
gfcFile,gfFile,gfrFile,isGFC,resModName,isOldFile) where
import Arch (selectLater, modifiedFiles, ModTime, getModTime,laterModTime)
@@ -251,6 +251,18 @@ getOptionsFromFile file = do
let ls = filter (isPrefixOf "--#") $ lines s
return $ fst $ getOptions "-" $ map (unwords . words . drop 3) ls
-- check if old GF file
isOldFile :: FilePath -> IO Bool
isOldFile f = do
s <- readFileIf f
let s' = unComm s
return $ not (null s') && old (head (words s'))
where
old = flip elem $ words
"cat category data def flags fun include lin lincat lindef lintype oper param pattern printname rule"
-- old GF tolerated newlines in quotes. No more supported!
fixNewlines s = case s of
'"':cs -> '"':mk cs

View File

@@ -53,7 +53,7 @@ data Command =
| CWrapTerm Ident
| CMorphoAnalyse
| CTestTokenizer
| CComputeConcrete I.Ident String
| CComputeConcrete String
| CTranslationQuiz Language Language
| CTranslationList Language Language Int
@@ -176,7 +176,11 @@ execC co@(comm, opts0) sa@((st,(h,_)),a) = case comm of
CMorphoAnalyse -> changeArg (AString . morphoAnalyse opts gro . prCommandArg) sa
CTestTokenizer -> changeArg (AString . optTokenizer opts gro . prCommandArg) sa
CComputeConcrete m t ->
CComputeConcrete t -> do
m <- return $
maybe (I.identC "?") id $ -- meaningful if no opers in t
maybe (resourceOfShellState st) (return . I.identC) $ -- topmost res
getOptVal opts useResource -- flag -res=m
justOutput (putStrLn (err id (prt . stripTerm) (
string2srcTerm src m t >>= Co.computeConcrete src))) sa

View File

@@ -76,7 +76,7 @@ pCommand ws = case ws of
----- "wt" : f : s -> aTerm (CWrapTerm (string2id f)) s
"ma" : s -> aString CMorphoAnalyse s
"tt" : s -> aString CTestTokenizer s
"cc" : m : s -> aUnit $ CComputeConcrete (pzIdent m) $ unwords s
"cc" : s -> aUnit $ CComputeConcrete $ unwords s
"tq" : i:o:[] -> aUnit (CTranslationQuiz (language i) (language o))
"tl":i:o:n:[] -> aUnit (CTranslationList (language i) (language o) (readIntArg n))