From 517992f3ba83a9a3ef4189e3f07a27dad12130e9 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Wed, 12 Jul 2023 19:22:46 +0200 Subject: [PATCH] added diagnostics for failed parser generation --- .../grammar/storage/ModuleParserStorage.rsc | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/org/rascalmpl/library/lang/rascal/grammar/storage/ModuleParserStorage.rsc b/src/org/rascalmpl/library/lang/rascal/grammar/storage/ModuleParserStorage.rsc index 86bfe380bf..647427cb90 100644 --- a/src/org/rascalmpl/library/lang/rascal/grammar/storage/ModuleParserStorage.rsc +++ b/src/org/rascalmpl/library/lang/rascal/grammar/storage/ModuleParserStorage.rsc @@ -43,10 +43,12 @@ import lang::rascal::grammar::definition::Modules; import lang::rascal::\syntax::Rascal; import util::Reflective; import util::FileSystem; +import util::Monitor; import Location; import ParseTree; import Grammar; import IO; +import Exception; @synopsis{For all modules in pcfg.srcs this will produce a `.parsers` stored parser capable of parsing concrete syntax fragment in said module.} @description{ @@ -116,18 +118,27 @@ void storeParsersForModules(set[Module] modules, PathConfig pcfg) { } void storeParserForModule(str main, loc file, set[Module] modules, PathConfig pcfg) { - // this has to be done from scratch due to different ways combining layout definitions - // with import and extend. Each main module has a different grammar because of this. - def = modules2definition(main, modules); + try { + // this has to be done from scratch due to different ways combining layout definitions + // with import and extend. Each main module has a different grammar because of this. + def = modules2definition(main, modules); - // here the layout semantics comes really into action - gr = fuse(def); + // here the layout semantics comes really into action + gr = fuse(def); - // find a file in the target folder to write to - target = pcfg.bin + relativize(pcfg.srcs, file)[extension="parsers"].path; + // find a file in the target folder to write to + target = pcfg.bin + relativize(pcfg.srcs, file)[extension="parsers"].path; - println("Generating parser for
at "); - if (type[Tree] rt := type(sort("Tree"), gr.rules)) { - storeParsers(rt, target); + println("Generating parser for
at "); + if (type[Tree] rt := type(sort("Tree"), gr.rules)) { + storeParsers(rt, target); + } + } + catch e:Java("JavaCompilation", str message, RuntimeException cause): { + jobWarning("Generated parser could not be compiled: + ' grammar: + ' error : + ' cause : "); + throw e; } }