mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-25 02:38:55 -06:00
New unicodings.
New unicodings. Module with works. Better compilation of old GF.
This commit is contained in:
@@ -36,7 +36,9 @@ string2annotTree gr m = annotate gr . string2absTerm (prt m) ---- prt
|
|||||||
|
|
||||||
shellStateFromFiles :: Options -> ShellState -> FilePath -> IOE ShellState
|
shellStateFromFiles :: Options -> ShellState -> FilePath -> IOE ShellState
|
||||||
shellStateFromFiles opts st file = do
|
shellStateFromFiles opts st file = do
|
||||||
let osb = addOptions (options [beVerbose, emitCode]) opts ---
|
let osb = if oElem showOld opts
|
||||||
|
then addOptions (options [beVerbose]) opts -- for old, no emit
|
||||||
|
else addOptions (options [beVerbose, emitCode]) opts -- for new, do
|
||||||
grts <- compileModule osb st file
|
grts <- compileModule osb st file
|
||||||
ioeErr $ updateShellState opts st grts
|
ioeErr $ updateShellState opts st grts
|
||||||
--- liftM (changeModTimes rts) $ grammar2shellState opts gr
|
--- liftM (changeModTimes rts) $ grammar2shellState opts gr
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ patt2term p = case p of
|
|||||||
anyTerm :: Term
|
anyTerm :: Term
|
||||||
anyTerm = LI (A.identC "_") --- should not happen
|
anyTerm = LI (A.identC "_") --- should not happen
|
||||||
|
|
||||||
|
matchPatt cs0 (FV ts) = liftM FV $ mapM (matchPatt cs0) ts
|
||||||
matchPatt cs0 trm = term2patt trm >>= match cs0 where
|
matchPatt cs0 trm = term2patt trm >>= match cs0 where
|
||||||
match cs t =
|
match cs t =
|
||||||
case cs of
|
case cs of
|
||||||
|
|||||||
@@ -54,6 +54,21 @@ batchCompileOld f = compileOld defOpts f
|
|||||||
|
|
||||||
compileModule :: Options -> ShellState -> FilePath ->
|
compileModule :: Options -> ShellState -> FilePath ->
|
||||||
IOE (GFC.CanonGrammar, (SourceGrammar,[(FilePath,ModTime)]))
|
IOE (GFC.CanonGrammar, (SourceGrammar,[(FilePath,ModTime)]))
|
||||||
|
compileModule opts st0 file | oElem showOld opts = do
|
||||||
|
let putp = putPointE opts
|
||||||
|
let path = [] ----
|
||||||
|
grammar1 <- putp ("- parsing old gf" +++ file) $ getOldGrammar opts file
|
||||||
|
let mods = modules grammar1
|
||||||
|
let env = compileEnvShSt st0 []
|
||||||
|
(_,sgr,cgr) <- foldM (comp putp path) env mods
|
||||||
|
return $ (reverseModules cgr, -- to preserve dependency order
|
||||||
|
(reverseModules sgr,[]))
|
||||||
|
where
|
||||||
|
comp putp path env sm0 = do
|
||||||
|
(k',sm) <- makeSourceModule opts env sm0
|
||||||
|
cm <- putp " generating code... " $ generateModuleCode opts path sm
|
||||||
|
extendCompileEnvInt env (k',sm,cm)
|
||||||
|
|
||||||
compileModule opts1 st0 file = do
|
compileModule opts1 st0 file = do
|
||||||
opts0 <- ioeIO $ getOptionsFromFile file
|
opts0 <- ioeIO $ getOptionsFromFile file
|
||||||
let useFileOpt = maybe False (const True) $ getOptVal opts0 pathList
|
let useFileOpt = maybe False (const True) $ getOptVal opts0 pathList
|
||||||
@@ -168,7 +183,6 @@ compileSourceModule opts env@(k,gr,can) mo@(i,mi) = do
|
|||||||
mo1 <- ioeErr $ rebuildModule mos mo
|
mo1 <- ioeErr $ rebuildModule mos mo
|
||||||
|
|
||||||
mo1b <- ioeErr $ extendModule mos mo1
|
mo1b <- ioeErr $ extendModule mos mo1
|
||||||
---- prDebug mo1b
|
|
||||||
|
|
||||||
case mo1b of
|
case mo1b of
|
||||||
(_,ModMod n) | not (isCompleteModule n) -> do
|
(_,ModMod n) | not (isCompleteModule n) -> do
|
||||||
@@ -185,8 +199,8 @@ compileSourceModule opts env@(k,gr,can) mo@(i,mi) = do
|
|||||||
|
|
||||||
return (k',mo4)
|
return (k',mo4)
|
||||||
where
|
where
|
||||||
prDebug mo = ioeIO $ putStrLn $ prGrammar $ MGrammar [mo] ---- debug
|
---- prDebug mo = ioeIO $ putStrLn $ prGrammar $ MGrammar [mo] ---- debug
|
||||||
|
prDebug mo = ioeIO $ print $ length $ lines $ prGrammar $ MGrammar [mo]
|
||||||
|
|
||||||
generateModuleCode :: Options -> InitPath -> SourceModule -> IOE GFC.CanonModule
|
generateModuleCode :: Options -> InitPath -> SourceModule -> IOE GFC.CanonModule
|
||||||
generateModuleCode opts path minfo@(name,info) = do
|
generateModuleCode opts path minfo@(name,info) = do
|
||||||
@@ -207,12 +221,14 @@ generateModuleCode opts path minfo@(name,info) = do
|
|||||||
return (gfcFile pname, code)
|
return (gfcFile pname, code)
|
||||||
if isCompilable info && emit && nomulti
|
if isCompilable info && emit && nomulti
|
||||||
then ioeIO $ writeFile file out >> putStr (" wrote file" +++ file)
|
then ioeIO $ writeFile file out >> putStr (" wrote file" +++ file)
|
||||||
else ioeIO $ putStrFlush "no need to save for this module "
|
else ioeIO $ putStrFlush $ "no need to save module" +++ prt name
|
||||||
return minfo'
|
return minfo'
|
||||||
where
|
where
|
||||||
isCompilable _ = True ---- isCompilableModule ---- emit code for interfaces
|
isCompilable mi = case mi of
|
||||||
|
ModMod m -> not $ isModCnc m && mstatus m == MSIncomplete
|
||||||
|
_ -> True
|
||||||
nomulti = not $ oElem makeMulti opts
|
nomulti = not $ oElem makeMulti opts
|
||||||
emit = oElem emitCode opts
|
emit = oElem emitCode opts && not (oElem notEmitCode opts)
|
||||||
optim = oElem optimizeCanon opts
|
optim = oElem optimizeCanon opts
|
||||||
|
|
||||||
-- for old GF: sort into modules, write files, compile as usual
|
-- for old GF: sort into modules, write files, compile as usual
|
||||||
@@ -220,7 +236,7 @@ generateModuleCode opts path minfo@(name,info) = do
|
|||||||
compileOld :: Options -> FilePath -> IOE GFC.CanonGrammar
|
compileOld :: Options -> FilePath -> IOE GFC.CanonGrammar
|
||||||
compileOld opts file = do
|
compileOld opts file = do
|
||||||
let putp = putPointE opts
|
let putp = putPointE opts
|
||||||
grammar1 <- putp ("- parsing old gf" +++ file) $ getOldGrammar file
|
grammar1 <- putp ("- parsing old gf" +++ file) $ getOldGrammar opts file
|
||||||
files <- mapM writeNewGF $ modules grammar1
|
files <- mapM writeNewGF $ modules grammar1
|
||||||
(_,_,grammar) <- foldM (compileOne opts) emptyCompileEnv files
|
(_,_,grammar) <- foldM (compileOne opts) emptyCompileEnv files
|
||||||
return grammar
|
return grammar
|
||||||
|
|||||||
@@ -33,11 +33,11 @@ getSourceModule file = do
|
|||||||
|
|
||||||
-- for old GF format with includes
|
-- for old GF format with includes
|
||||||
|
|
||||||
getOldGrammar :: FilePath -> IOE SourceGrammar
|
getOldGrammar :: Options -> FilePath -> IOE SourceGrammar
|
||||||
getOldGrammar file = do
|
getOldGrammar opts file = do
|
||||||
defs <- parseOldGrammarFiles file
|
defs <- parseOldGrammarFiles file
|
||||||
let g = A.OldGr A.NoIncl defs
|
let g = A.OldGr A.NoIncl defs
|
||||||
ioeErr $ transOldGrammar g file
|
ioeErr $ transOldGrammar opts file g
|
||||||
|
|
||||||
parseOldGrammarFiles :: FilePath -> IOE [A.TopDef]
|
parseOldGrammarFiles :: FilePath -> IOE [A.TopDef]
|
||||||
parseOldGrammarFiles file = do
|
parseOldGrammarFiles file = do
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ beVerbose = iOpt "v"
|
|||||||
showInfo = iOpt "i"
|
showInfo = iOpt "i"
|
||||||
beSilent = iOpt "s"
|
beSilent = iOpt "s"
|
||||||
emitCode = iOpt "o"
|
emitCode = iOpt "o"
|
||||||
|
notEmitCode = iOpt "noemit"
|
||||||
makeMulti = iOpt "multi"
|
makeMulti = iOpt "multi"
|
||||||
beShort = iOpt "short"
|
beShort = iOpt "short"
|
||||||
wholeGrammar = iOpt "w"
|
wholeGrammar = iOpt "w"
|
||||||
@@ -193,6 +194,11 @@ extractGr = aOpt "extract"
|
|||||||
pathList = aOpt "path"
|
pathList = aOpt "path"
|
||||||
uniCoding = aOpt "coding"
|
uniCoding = aOpt "coding"
|
||||||
|
|
||||||
|
useName = aOpt "name"
|
||||||
|
useAbsName = aOpt "abs"
|
||||||
|
useCncName = aOpt "cnc"
|
||||||
|
useResName = aOpt "res"
|
||||||
|
|
||||||
markLin = aOpt "mark"
|
markLin = aOpt "mark"
|
||||||
markOptXML = oArg "xml"
|
markOptXML = oArg "xml"
|
||||||
markOptJava = oArg "java"
|
markOptJava = oArg "java"
|
||||||
|
|||||||
@@ -139,9 +139,6 @@ execLine put (c@(co, os), arg, cs) (outps,st) = do
|
|||||||
execC :: CommandOpt -> ShellIO
|
execC :: CommandOpt -> ShellIO
|
||||||
execC co@(comm, opts0) sa@((st,(h,_)),a) = case comm of
|
execC co@(comm, opts0) sa@((st,(h,_)),a) = case comm of
|
||||||
|
|
||||||
--- read old GF and write into files; no update of st yet
|
|
||||||
CImport file | oElem showOld opts -> useIOE sa $ batchCompileOld file >> return sa
|
|
||||||
|
|
||||||
CImport file -> useIOE sa $ do
|
CImport file -> useIOE sa $ do
|
||||||
st1 <- shellStateFromFiles opts st file
|
st1 <- shellStateFromFiles opts st file
|
||||||
ioeIO $ changeState (const st1) sa --- \ ((_,h),a) -> ((st,h), a))
|
ioeIO $ changeState (const st1) sa --- \ ((_,h),a) -> ((st,h), a))
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import AbsGF
|
|||||||
import PrintGF
|
import PrintGF
|
||||||
import RemoveLiT --- for bw compat
|
import RemoveLiT --- for bw compat
|
||||||
import Operations
|
import Operations
|
||||||
|
import Option
|
||||||
|
|
||||||
import Monad
|
import Monad
|
||||||
import Char
|
import Char
|
||||||
@@ -482,8 +483,8 @@ transDDecl x = case x of
|
|||||||
-- to deal with the old format, sort judgements in three modules, forming
|
-- to deal with the old format, sort judgements in three modules, forming
|
||||||
-- their names from a given string, e.g. file name or overriding user-given string
|
-- their names from a given string, e.g. file name or overriding user-given string
|
||||||
|
|
||||||
transOldGrammar :: OldGrammar -> String -> Err G.SourceGrammar
|
transOldGrammar :: Options -> FilePath -> OldGrammar -> Err G.SourceGrammar
|
||||||
transOldGrammar x name = case x of
|
transOldGrammar opts name0 x = case x of
|
||||||
OldGr includes topdefs -> do --- includes must be collected separately
|
OldGr includes topdefs -> do --- includes must be collected separately
|
||||||
let moddefs = sortTopDefs topdefs
|
let moddefs = sortTopDefs topdefs
|
||||||
g1 <- transGrammar $ Gr moddefs
|
g1 <- transGrammar $ Gr moddefs
|
||||||
@@ -515,9 +516,10 @@ transOldGrammar x name = case x of
|
|||||||
ne = NoExt
|
ne = NoExt
|
||||||
q = CMCompl
|
q = CMCompl
|
||||||
|
|
||||||
absName = identC topic
|
name = maybe name0 (++ ".gf") $ getOptVal opts useName
|
||||||
resName = identC ("Res" ++ lang)
|
absName = identC $ maybe topic id $ getOptVal opts useAbsName
|
||||||
cncName = identC lang
|
resName = identC $ maybe ("Res" ++ lang) id $ getOptVal opts useResName
|
||||||
|
cncName = identC $ maybe lang id $ getOptVal opts useCncName
|
||||||
|
|
||||||
(beg,rest) = span (/='.') name
|
(beg,rest) = span (/='.') name
|
||||||
(topic,lang) = case rest of -- to avoid overwriting old files
|
(topic,lang) = case rest of -- to avoid overwriting old files
|
||||||
|
|||||||
@@ -1,13 +1,28 @@
|
|||||||
module Hebrew where
|
module Hebrew where
|
||||||
|
|
||||||
mkHebrew :: String -> String
|
mkHebrew :: String -> String
|
||||||
mkHebrew = reverse . unwords . (map mkHebrewWord) . words
|
mkHebrew = mkHebrewWord
|
||||||
--- reverse : assumes everything's on same line
|
--- reverse : assumes everything's on same line
|
||||||
|
|
||||||
type HebrewChar = Char
|
type HebrewChar = Char
|
||||||
|
|
||||||
|
-- HH 031103 added code for spooling the markup
|
||||||
|
-- removed reverse, words, unwords (seemed obsolete and come out wrong on the screen)
|
||||||
|
|
||||||
mkHebrewWord :: String -> [HebrewChar]
|
mkHebrewWord :: String -> [HebrewChar]
|
||||||
mkHebrewWord = map mkHebrewChar
|
-- mkHebrewWord = map mkHebrewChar
|
||||||
|
|
||||||
|
mkHebrewWord s = case s of
|
||||||
|
[] -> []
|
||||||
|
'<' : cs -> '<' : spoolMarkup cs
|
||||||
|
' ' : cs -> ' ' : mkHebrewWord cs
|
||||||
|
c1 : cs -> mkHebrewChar c1 : mkHebrewWord cs
|
||||||
|
|
||||||
|
spoolMarkup :: String -> String
|
||||||
|
spoolMarkup s = case s of
|
||||||
|
[] -> [] -- Shouldn't happen
|
||||||
|
'>' : cs -> '>' : mkHebrewWord cs
|
||||||
|
c1 : cs -> c1 : spoolMarkup cs
|
||||||
|
|
||||||
mkHebrewChar c = case lookup c cc of Just c' -> c' ; _ -> c
|
mkHebrewChar c = case lookup c cc of Just c' -> c' ; _ -> c
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -4,6 +4,13 @@ import Greek (mkGreek)
|
|||||||
import Arabic (mkArabic)
|
import Arabic (mkArabic)
|
||||||
import Hebrew (mkHebrew)
|
import Hebrew (mkHebrew)
|
||||||
import Russian (mkRussian, mkRusKOI8)
|
import Russian (mkRussian, mkRusKOI8)
|
||||||
|
import Ethiopic (mkEthiopic)
|
||||||
|
import Tamil (mkTamil)
|
||||||
|
import OCSCyrillic (mkOCSCyrillic)
|
||||||
|
import LatinASupplement (mkLatinASupplement)
|
||||||
|
import Devanagari (mkDevanagari)
|
||||||
|
import Hiragana (mkJapanese)
|
||||||
|
import ExtendedArabic (mkExtendedArabic)
|
||||||
|
|
||||||
-- ad hoc Unicode conversions from different alphabets
|
-- ad hoc Unicode conversions from different alphabets
|
||||||
|
|
||||||
@@ -15,6 +22,13 @@ mkUnicode s = case s of
|
|||||||
'/':'-':cs -> mkArabic (remClosing cs)
|
'/':'-':cs -> mkArabic (remClosing cs)
|
||||||
'/':'_':cs -> mkRussian (remClosing cs)
|
'/':'_':cs -> mkRussian (remClosing cs)
|
||||||
'/':'*':cs -> mkRusKOI8 (remClosing cs)
|
'/':'*':cs -> mkRusKOI8 (remClosing cs)
|
||||||
|
'/':'E':cs -> mkEthiopic (remClosing cs)
|
||||||
|
'/':'T':cs -> mkTamil (remClosing cs)
|
||||||
|
'/':'C':cs -> mkOCSCyrillic (remClosing cs)
|
||||||
|
'/':'&':cs -> mkDevanagari (remClosing cs)
|
||||||
|
'/':'L':cs -> mkLatinASupplement (remClosing cs)
|
||||||
|
'/':'J':cs -> mkJapanese (remClosing cs)
|
||||||
|
'/':'A':cs -> mkExtendedArabic (remClosing cs)
|
||||||
_ -> s
|
_ -> s
|
||||||
|
|
||||||
remClosing cs
|
remClosing cs
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
module Today where today = "Thu Nov 13 17:50:30 CET 2003"
|
module Today where today = "Fri Nov 14 14:23:19 CET 2003"
|
||||||
|
|||||||
Reference in New Issue
Block a user