diff options
| author | aarne <unknown> | 2004-04-01 09:51:32 +0000 |
|---|---|---|
| committer | aarne <unknown> | 2004-04-01 09:51:32 +0000 |
| commit | f53f35978f4cd6b0e4c5e9123b5e88f04f6f4452 (patch) | |
| tree | 100fc2f36a0dccc24c030b5a82389dac70780902 /src/GF | |
| parent | 3f9b4e7855cf4594708a9fbad194c89540d2cf1e (diff) | |
2beta2
Diffstat (limited to 'src/GF')
| -rw-r--r-- | src/GF/API/IOGrammar.hs | 12 | ||||
| -rw-r--r-- | src/GF/Compile/Compile.hs | 5 | ||||
| -rw-r--r-- | src/GF/Compile/ShellState.hs | 14 | ||||
| -rw-r--r-- | src/GF/Infra/Option.hs | 1 | ||||
| -rw-r--r-- | src/GF/Infra/ReadFiles.hs | 14 | ||||
| -rw-r--r-- | src/GF/Shell.hs | 8 | ||||
| -rw-r--r-- | src/GF/Shell/PShell.hs | 2 |
7 files changed, 46 insertions, 10 deletions
diff --git a/src/GF/API/IOGrammar.hs b/src/GF/API/IOGrammar.hs index b535c9be0..83823be16 100644 --- a/src/GF/API/IOGrammar.hs +++ b/src/GF/API/IOGrammar.hs @@ -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 diff --git a/src/GF/Compile/Compile.hs b/src/GF/Compile/Compile.hs index 145ada8a9..88f601a18 100644 --- a/src/GF/Compile/Compile.hs +++ b/src/GF/Compile/Compile.hs @@ -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" diff --git a/src/GF/Compile/ShellState.hs b/src/GF/Compile/ShellState.hs index 7c674a0dc..9bfc4a048 100644 --- a/src/GF/Compile/ShellState.hs +++ b/src/GF/Compile/ShellState.hs @@ -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) diff --git a/src/GF/Infra/Option.hs b/src/GF/Infra/Option.hs index fe56c23fc..abfb44e5a 100644 --- a/src/GF/Infra/Option.hs +++ b/src/GF/Infra/Option.hs @@ -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" diff --git a/src/GF/Infra/ReadFiles.hs b/src/GF/Infra/ReadFiles.hs index 4172ee32e..46091c6b5 100644 --- a/src/GF/Infra/ReadFiles.hs +++ b/src/GF/Infra/ReadFiles.hs @@ -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 diff --git a/src/GF/Shell.hs b/src/GF/Shell.hs index 5136a00d0..7574b86a6 100644 --- a/src/GF/Shell.hs +++ b/src/GF/Shell.hs @@ -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 diff --git a/src/GF/Shell/PShell.hs b/src/GF/Shell/PShell.hs index 0157112c8..c2db72e63 100644 --- a/src/GF/Shell/PShell.hs +++ b/src/GF/Shell/PShell.hs @@ -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)) |
