use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.DefaultCodeSection in project legend-engine by finos.
the class CorePureGrammarParser method parseDataSection.
private static Section parseDataSection(SectionSourceCode sectionSourceCode, Consumer<PackageableElement> elementConsumer, PureGrammarParserContext pureGrammarParserContext) {
SourceCodeParserInfo parserInfo = getDataParserInfo(sectionSourceCode);
DefaultCodeSection section = new DefaultCodeSection();
section.parserName = sectionSourceCode.sectionType;
section.sourceInformation = parserInfo.sourceInformation;
DataParseTreeWalker walker = new DataParseTreeWalker(parserInfo.walkerSourceInformation, elementConsumer, section, pureGrammarParserContext.getPureGrammarParserExtensions());
walker.visit((DataParserGrammar.DefinitionContext) parserInfo.rootContext);
return section;
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.DefaultCodeSection in project legend-engine by finos.
the class DataSpaceParserExtension method parseSection.
private static Section parseSection(SectionSourceCode sectionSourceCode, Consumer<PackageableElement> elementConsumer, PureGrammarParserContext pureGrammarParserContext) {
SourceCodeParserInfo parserInfo = getDataSpaceParserInfo(sectionSourceCode);
DefaultCodeSection section = new DefaultCodeSection();
section.parserName = sectionSourceCode.sectionType;
section.sourceInformation = parserInfo.sourceInformation;
DataSpaceParseTreeWalker walker = new DataSpaceParseTreeWalker(parserInfo.walkerSourceInformation, elementConsumer, section);
walker.visit((DataSpaceParserGrammar.DefinitionContext) parserInfo.rootContext);
return section;
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.DefaultCodeSection in project legend-engine by finos.
the class PureGrammarParser method visitSection.
private Section visitSection(CodeParserGrammar.SectionContext ctx, DEPRECATED_PureGrammarParserLibrary parserLibrary, ParseTreeWalkerSourceInformation walkerSourceInformation, PureGrammarParserContext parserContext, Consumer<PackageableElement> elementConsumer, boolean returnSourceInfo) {
// the prefix is `\n###` hence 4 characters
String parserName = ctx.SECTION_START().getText().substring(4);
SourceInformation parserNameSourceInformation = walkerSourceInformation.getSourceInformation(ctx.SECTION_START().getSymbol());
// since the CODE_BLOCK_START is `\n###` we have to subtract 1 more line than usual
int lineOffset = ctx.SECTION_START().getSymbol().getLine() - 2;
ParseTreeWalkerSourceInformation sectionWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder("", lineOffset, 0).withReturnSourceInfo(returnSourceInfo).build();
SourceInformation sectionSourceInformation = walkerSourceInformation.getSourceInformation(ctx);
if (ctx.sectionContent() != null) {
try {
StringBuilder codeBuilder = new StringBuilder();
for (CodeParserGrammar.SectionContentContext tn : ctx.sectionContent()) {
codeBuilder.append(tn.getText());
}
SectionSourceCode codeSection = new SectionSourceCode(codeBuilder.toString(), parserName, sectionSourceInformation, sectionWalkerSourceInformation);
SectionParser sectionParser = this.extensions.getExtraSectionParser(parserName);
Section section;
if (sectionParser == null) {
DEPRECATED_SectionGrammarParser legacyParser = parserLibrary.getParser(parserName, parserNameSourceInformation);
if (legacyParser == null) {
throw new EngineException("'" + parserName + "' is not a known section parser", parserNameSourceInformation, EngineErrorType.PARSER);
}
section = legacyParser.parse(legacyParser.getParserInfo(codeSection.code, codeSection.sourceInformation, codeSection.walkerSourceInformation), elementConsumer, parserContext);
} else {
section = sectionParser.parse(codeSection, elementConsumer, parserContext);
}
// remove duplicates in imports and content of the section
section.elements = ListIterate.distinct(section.elements);
if (section instanceof ImportAwareCodeSection) {
((ImportAwareCodeSection) section).imports = ListIterate.distinct(((ImportAwareCodeSection) section).imports);
}
return section;
} catch (RuntimeException e) {
EngineException engineException = EngineException.findException(e);
if (engineException != null && engineException.getSourceInformation() != null) {
throw engineException;
}
String message = e instanceof UnsupportedOperationException && (e.getMessage() == null || e.getMessage().isEmpty()) ? "Unsupported syntax" : e instanceof NullPointerException ? "An exception of type 'NullPointerException' occurred, please notify developer" : e.getMessage();
LOGGER.error(new LogInfo(null, LoggingEventType.GRAMMAR_PARSING_ERROR, message).toString(), e);
throw new EngineException(message, sectionSourceInformation, EngineErrorType.PARSER, e);
}
}
// create default section for empty section
Section section = new DefaultCodeSection();
section.parserName = parserName;
section.sourceInformation = sectionSourceInformation;
return section;
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.DefaultCodeSection in project legend-engine by finos.
the class TextParserExtension method parseSection.
private static Section parseSection(SectionSourceCode sectionSourceCode, Consumer<PackageableElement> elementConsumer, PureGrammarParserContext pureGrammarParserContext) {
SourceCodeParserInfo parserInfo = getTextParserInfo(sectionSourceCode);
DefaultCodeSection section = new DefaultCodeSection();
section.parserName = sectionSourceCode.sectionType;
section.sourceInformation = parserInfo.sourceInformation;
TextParseTreeWalker walker = new TextParseTreeWalker(parserInfo.walkerSourceInformation, elementConsumer, section);
walker.visit((TextParserGrammar.DefinitionContext) parserInfo.rootContext);
return section;
}
Aggregations