forked from GitHub/gf-core
mergePGF now detects when grammars have different abstract syntaxes
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -395,10 +395,15 @@ void PgfReader::merge_abstract(ref<PgfAbstr> abstract)
|
||||
{
|
||||
this->abstract = abstract;
|
||||
|
||||
read_name(); // ?
|
||||
merge_namespace<PgfFlag>(&PgfReader::read_flag); // ?
|
||||
merge_namespace<PgfAbsFun>(&PgfReader::read_absfun); // ?
|
||||
merge_namespace<PgfAbsCat>(&PgfReader::read_abscat); // ?
|
||||
ref<PgfText> 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<PgfFlag>(&PgfReader::read_flag);
|
||||
merge_namespace<PgfAbsFun>(&PgfReader::read_absfun);
|
||||
merge_namespace<PgfAbsCat>(&PgfReader::read_abscat);
|
||||
}
|
||||
|
||||
ref<PgfLParam> PgfReader::read_lparam()
|
||||
|
||||
Reference in New Issue
Block a user