1
0
forked from GitHub/gf-core

mergePGF now detects when grammars have different abstract syntaxes

This commit is contained in:
krangelov
2021-12-24 16:19:14 +01:00
parent 21d38a7b4a
commit 8b602d6c9f
2 changed files with 17 additions and 5 deletions

View File

@@ -20,6 +20,7 @@ import System.Directory
import qualified Data.Set as Set import qualified Data.Set as Set
import qualified Data.Map as Map import qualified Data.Map as Map
import Control.Monad(foldM) import Control.Monad(foldM)
import Control.Exception(catch,throwIO)
-- import a grammar in an environment where it extends an existing grammar -- import a grammar in an environment where it extends an existing grammar
importGrammar :: Maybe PGF -> Options -> [FilePath] -> IO (Maybe PGF) importGrammar :: Maybe PGF -> Options -> [FilePath] -> IO (Maybe PGF)
@@ -65,7 +66,13 @@ importPGF opts Nothing f
putStr ("(Boot image "++f'++") ") putStr ("(Boot image "++f'++") ")
fmap Just (bootNGF f f') fmap Just (bootNGF f f')
| otherwise = fmap Just (readPGF 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 :: Options -> [FilePath] -> IO (ModuleName,SourceGrammar)
importSource opts files = fmap snd (batchCompile opts files) importSource opts files = fmap snd (batchCompile opts files)

View File

@@ -395,10 +395,15 @@ void PgfReader::merge_abstract(ref<PgfAbstr> abstract)
{ {
this->abstract = abstract; this->abstract = abstract;
read_name(); // ? ref<PgfText> name = read_name();
merge_namespace<PgfFlag>(&PgfReader::read_flag); // ? int cmp = textcmp(&(*abstract->name), &(*name));
merge_namespace<PgfAbsFun>(&PgfReader::read_absfun); // ? PgfDB::free(name);
merge_namespace<PgfAbsCat>(&PgfReader::read_abscat); // ? 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() ref<PgfLParam> PgfReader::read_lparam()