summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Grammar
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2011-11-15 19:12:22 +0000
committerkr.angelov <kr.angelov@gmail.com>2011-11-15 19:12:22 +0000
commita2626e24dd9e468ee0c5ccd455e4a5f782d56522 (patch)
treec222b77a1b7ccba40b3bd244ae00f1945eb3a3c8 /src/compiler/GF/Grammar
parent8a10aa5cf969caf482a7e852562caad815d74672 (diff)
now we store version number in every .gfo file. If the file is compiled with different compiler then we simply recompile it.
Diffstat (limited to 'src/compiler/GF/Grammar')
-rw-r--r--src/compiler/GF/Grammar/Binary.hs31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/compiler/GF/Grammar/Binary.hs b/src/compiler/GF/Grammar/Binary.hs
index d1a3ac413..20adf3c48 100644
--- a/src/compiler/GF/Grammar/Binary.hs
+++ b/src/compiler/GF/Grammar/Binary.hs
@@ -9,7 +9,9 @@
module GF.Grammar.Binary where
+import Data.Char
import Data.Binary
+import Control.Monad
import qualified Data.Map as Map
import qualified Data.ByteString.Char8 as BS
@@ -18,7 +20,11 @@ import GF.Infra.Ident
import GF.Infra.Option
import GF.Grammar.Grammar
-import PGF.Binary hiding (decodingError)
+import PGF.Binary
+
+-- Please change this every time when the GFO format is changed
+gfoVersion = "GF01"
+
instance Binary Ident where
put id = put (ident2bs id)
@@ -274,9 +280,24 @@ instance Binary Label where
1 -> fmap LVar get
_ -> decodingError
-decodeModHeader :: FilePath -> IO SourceModule
-decodeModHeader fpath = do
- (m,mtype,mstatus,mflags,mextend,mwith,mopens,med,msrc) <- decodeFile fpath
+
+putGFOVersion = mapM_ (putWord8 . fromIntegral . ord) gfoVersion
+getGFOVersion = replicateM (length gfoVersion) (fmap (chr . fromIntegral) getWord8)
+
+decodeModule :: FilePath -> IO SourceModule
+decodeModule fpath = do
+ (m,mtype,mstatus,mflags,mextend,mwith,mopens,med,msrc) <- decodeFile_ fpath (getGFOVersion >> get)
return (m,ModInfo mtype mstatus mflags mextend mwith mopens med msrc Nothing Map.empty)
-decodingError = fail "This GFO file was compiled with different version of GF"
+decodeModuleHeader fpath = decodeFile_ fpath getVersionedMod
+ where
+ getVersionedMod = do
+ ver <- getGFOVersion
+ if ver == gfoVersion
+ then do (m,mtype,mstatus,mflags,mextend,mwith,mopens,med,msrc) <- get
+ return (Just (m,ModInfo mtype mstatus mflags mextend mwith mopens med msrc Nothing Map.empty))
+ else return Nothing
+
+encodeModule :: FilePath -> SourceModule -> IO ()
+encodeModule fpath mo =
+ encodeFile_ fpath (putGFOVersion >> put mo)