diff --git a/src/compiler/GF/Command/Importing.hs b/src/compiler/GF/Command/Importing.hs index f9c04efd7..d8e498c96 100644 --- a/src/compiler/GF/Command/Importing.hs +++ b/src/compiler/GF/Command/Importing.hs @@ -20,6 +20,7 @@ import System.Directory import qualified Data.Set as Set import qualified Data.Map as Map import Control.Monad(foldM) +import Control.Exception(catch,throwIO) -- import a grammar in an environment where it extends an existing grammar importGrammar :: Maybe PGF -> Options -> [FilePath] -> IO (Maybe PGF) @@ -65,7 +66,13 @@ importPGF opts Nothing f putStr ("(Boot image "++f'++") ") fmap Just (bootNGF f f') | otherwise = fmap Just (readPGF f) -importPGF opts (Just pgf) f = fmap Just (modifyPGF pgf (mergePGF f)) +importPGF opts (Just pgf) f = fmap Just (modifyPGF pgf (mergePGF f) `catch` + (\e@(PGFError loc msg) -> + if msg == "The abstract syntax names doesn't match" + then do putStrLn (msg++", previous concretes discarded.") + readPGF f + else throwIO e)) + importSource :: Options -> [FilePath] -> IO (ModuleName,SourceGrammar) importSource opts files = fmap snd (batchCompile opts files) diff --git a/src/runtime/c/pgf/reader.cxx b/src/runtime/c/pgf/reader.cxx index 0b7c1d50a..693a119d6 100644 --- a/src/runtime/c/pgf/reader.cxx +++ b/src/runtime/c/pgf/reader.cxx @@ -395,10 +395,15 @@ void PgfReader::merge_abstract(ref abstract) { this->abstract = abstract; - read_name(); // ? - merge_namespace(&PgfReader::read_flag); // ? - merge_namespace(&PgfReader::read_absfun); // ? - merge_namespace(&PgfReader::read_abscat); // ? + ref name = read_name(); + int cmp = textcmp(&(*abstract->name), &(*name)); + PgfDB::free(name); + if (cmp != 0) + throw pgf_error("The abstract syntax names doesn't match"); + + merge_namespace(&PgfReader::read_flag); + merge_namespace(&PgfReader::read_absfun); + merge_namespace(&PgfReader::read_abscat); } ref PgfReader::read_lparam()