use of org.spoofax.jsglr2.parsetable.ParseTableReadException in project spoofax by metaborg.
the class JSGLRParseService method parse.
@Override
public ISpoofaxParseUnit parse(ISpoofaxInputUnit input, IProgress progress, ICancel cancel) throws ParseException {
final FileObject source = input.source();
final ILanguageImpl langImpl;
final ILanguageImpl base;
if (input.dialect() != null) {
langImpl = input.dialect();
base = input.langImpl();
} else {
langImpl = input.langImpl();
base = null;
}
final String text = input.text();
final ITermFactory termFactory = termFactoryService.get(langImpl, null, false);
final IParserConfig config;
JSGLRParserConfiguration parserConfig = input.config();
if (parserConfig == null) {
parserConfig = defaultParserConfig;
}
if (parserConfig.completion) {
config = getCompletionParserConfig(langImpl, input);
} else {
config = getParserConfig(langImpl, input);
}
try {
logger.trace("Parsing {}", source);
JSGLRVersion version = jsglrVersion(input);
final JSGLRI<?> parser;
boolean dataDependentParsing = false;
for (ILanguageComponent component : langImpl.components()) {
if (component.config().dataDependent()) {
dataDependentParsing = true;
}
}
if (version == JSGLRVersion.v2) {
if (dataDependentParsing) {
parser = new JSGLR2I(config, termFactory, langImpl, null, source, text, true);
} else {
parser = new JSGLR2I(config, termFactory, langImpl, null, source, text, false);
}
} else {
if (base != null) {
parser = new JSGLR1I(config, termFactory, base, langImpl, source, text);
} else {
parser = new JSGLR1I(config, termFactory, langImpl, null, source, text);
}
}
final ParseContrib contrib = parser.parse(parserConfig);
if (version == JSGLRVersion.v2) {
if (contrib.valid)
logger.info("Valid JSGLR2 parse");
else
logger.info("Invalid JSGLR2 parse");
}
final ISpoofaxParseUnit unit = unitService.parseUnit(input, contrib);
return unit;
} catch (IOException | InvalidParseTableException | ParseTableReadException e) {
throw new ParseException(input, e);
}
}
Aggregations