use of org.finos.legend.engine.language.pure.grammar.from.extension.MappingElementParser in project legend-engine by finos.
the class AggregationAwareMappingParseTreeWalker method visitModelOperationContext.
private void visitModelOperationContext(AggregationAwareParserGrammar.ModelOperationContext ctx, AggregateSetImplementationContainer aggregateSetImplementationContainer) {
int startLine = ctx.start.getLine();
int lineOffset = walkerSourceInformation.getLineOffset() + startLine - 1;
int columnOffset = (startLine == 1 ? walkerSourceInformation.getColumnOffset() : 0) + ctx.BRACE_OPEN().getSymbol().getCharPositionInLine() + ctx.BRACE_OPEN().getText().length();
MappingElementParser extraParser = this.parserContext.getPureGrammarParserExtensions().getExtraMappingElementParser("AggregateSpecification");
String inputText = this.input.getText(new Interval(ctx.BRACE_OPEN().getSymbol().getStartIndex() + 1, ctx.MAPPING_ISLAND_BRACE_CLOSE().getSymbol().getStartIndex() - 1));
ParseTreeWalkerSourceInformation sourceInformation = new ParseTreeWalkerSourceInformation.Builder(walkerSourceInformation.getSourceId(), lineOffset, columnOffset).withReturnSourceInfo(this.walkerSourceInformation.getReturnSourceInfo()).build();
MappingElementSourceCode sourceCode = new MappingElementSourceCode(inputText, "AggregateSpecification", sourceInformation, this.mappingElementSourceCode.mappingElementParserRuleContext, this.walkerSourceInformation);
Object element = extraParser.parse(sourceCode, this.parserContext);
if (element instanceof AggregateSpecification) {
aggregateSetImplementationContainer.aggregateSpecification = (AggregateSpecification) element;
} else {
throw new EngineException("Invalid parser result for " + mappingElementSourceCode.name + ": " + element, this.walkerSourceInformation.getSourceInformation(ctx), EngineErrorType.PARSER);
}
}
use of org.finos.legend.engine.language.pure.grammar.from.extension.MappingElementParser in project legend-engine by finos.
the class AggregationAwareMappingParseTreeWalker method visitAggregateMappingContext.
private void visitAggregateMappingContext(AggregationAwareParserGrammar.AggregateMappingContext ctx, AggregateSetImplementationContainer aggregateSetImplementationContainer, AggregationAwareClassMapping parent) {
String parserName = ctx.parserName().getText();
int startLine = ctx.BRACE_OPEN().getSymbol().getLine();
int lineOffset = walkerSourceInformation.getLineOffset() + startLine - 1;
int columnOffset = (startLine == 1 ? walkerSourceInformation.getColumnOffset() : 0) + ctx.BRACE_OPEN().getSymbol().getCharPositionInLine() + ctx.BRACE_OPEN().getText().length();
MappingElementParser extraParser = this.parserContext.getPureGrammarParserExtensions().getExtraMappingElementParser(parserName);
String mappingInput = this.input.getText(new Interval(ctx.BRACE_OPEN().getSymbol().getStartIndex() + 1, ctx.MAPPING_ISLAND_BRACE_CLOSE().getSymbol().getStartIndex() - 1));
ParseTreeWalkerSourceInformation mappingElementWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(this.walkerSourceInformation.getSourceId(), lineOffset, columnOffset).withReturnSourceInfo(this.walkerSourceInformation.getReturnSourceInfo()).build();
MappingElementSourceCode mappingElementSourceCode = new MappingElementSourceCode(mappingInput, parserName, mappingElementWalkerSourceInformation, this.mappingElementSourceCode.mappingElementParserRuleContext, this.walkerSourceInformation);
Object mappingElement = extraParser.parse(mappingElementSourceCode, this.parserContext);
if (mappingElement instanceof ClassMapping) {
ClassMapping classMapping = (ClassMapping) mappingElement;
classMapping.id = classMapping.id == null ? parent.id + "_Aggregate_" + aggregateSetImplementationContainer.index : classMapping.id + "_Aggregate_" + aggregateSetImplementationContainer.index;
aggregateSetImplementationContainer.setImplementation = classMapping;
} else {
throw new EngineException("Invalid parser result for " + mappingElementSourceCode.name + ": " + mappingElement, this.walkerSourceInformation.getSourceInformation(ctx), EngineErrorType.PARSER);
}
}
use of org.finos.legend.engine.language.pure.grammar.from.extension.MappingElementParser in project legend-engine by finos.
the class MappingParseTreeWalker method visitMappingElement.
private Mapping visitMappingElement(MappingParserGrammar.MappingElementContext ctx, Mapping mapping) {
String parserName = ctx.parserName().getText();
// Construct the mapping element string (with spacing) to be dispatched to another parser
// NOTE: we want to preserve the spacing so we can correctly produce source information in the dispatched parser
StringBuilder mappingElementStringBuilder = new StringBuilder();
for (MappingParserGrammar.MappingElementBodyContentContext fragment : ctx.mappingElementBody().mappingElementBodyContent()) {
mappingElementStringBuilder.append(fragment.getText());
}
String mappingElementCode = mappingElementStringBuilder.length() > 0 ? mappingElementStringBuilder.substring(0, mappingElementStringBuilder.length() - 1) : mappingElementStringBuilder.toString();
// prepare island grammar walker source information
int startLine = ctx.mappingElementBody().BRACE_OPEN().getSymbol().getLine();
int lineOffset = walkerSourceInformation.getLineOffset() + startLine - 1;
// only add current walker source information column offset if this is the first line
int columnOffset = (startLine == 1 ? walkerSourceInformation.getColumnOffset() : 0) + ctx.mappingElementBody().BRACE_OPEN().getSymbol().getCharPositionInLine() + ctx.mappingElementBody().BRACE_OPEN().getText().length();
ParseTreeWalkerSourceInformation mappingElementWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(mapping.getPath(), lineOffset, columnOffset).withReturnSourceInfo(this.walkerSourceInformation.getReturnSourceInfo()).build();
MappingElementSourceCode mappingElementSourceCode = new MappingElementSourceCode(mappingElementCode, parserName, mappingElementWalkerSourceInformation, ctx, this.walkerSourceInformation);
MappingElementParser extraParser = this.extensions.getExtraMappingElementParser(mappingElementSourceCode.name);
if (extraParser == null) {
throw new EngineException("No parser for " + mappingElementSourceCode.name, this.walkerSourceInformation.getSourceInformation(ctx), EngineErrorType.PARSER);
}
Object mappingElement = extraParser.parse(mappingElementSourceCode, this.parserContext);
if (mappingElement instanceof ClassMapping) {
mapping.classMappings.add((ClassMapping) mappingElement);
} else if (mappingElement instanceof EnumerationMapping) {
mapping.enumerationMappings.add((EnumerationMapping) mappingElement);
} else if (mappingElement instanceof AssociationMapping) {
mapping.associationMappings.add((AssociationMapping) mappingElement);
} else {
throw new EngineException("Invalid parser result for " + mappingElementSourceCode.name + ": " + mappingElement, this.walkerSourceInformation.getSourceInformation(ctx), EngineErrorType.PARSER);
}
return mapping;
}
use of org.finos.legend.engine.language.pure.grammar.from.extension.MappingElementParser in project legend-engine by finos.
the class AggregationAwareMappingParseTreeWalker method visitMainMapping.
private void visitMainMapping(AggregationAwareParserGrammar.MainMappingContext ctx, AggregationAwareClassMapping mapping) {
String parserName = ctx.parserName().getText();
int startLine = ctx.BRACE_OPEN().getSymbol().getLine();
int lineOffset = walkerSourceInformation.getLineOffset() + startLine - 1;
int columnOffset = (startLine == 1 ? walkerSourceInformation.getColumnOffset() : 0) + ctx.BRACE_OPEN().getSymbol().getCharPositionInLine() + ctx.BRACE_OPEN().getText().length();
MappingElementParser extraParser = this.parserContext.getPureGrammarParserExtensions().getExtraMappingElementParser(parserName);
String mappingInput = this.input.getText(new Interval(ctx.BRACE_OPEN().getSymbol().getStartIndex() + 1, ctx.MAPPING_ISLAND_BRACE_CLOSE().getSymbol().getStartIndex() - 1));
ParseTreeWalkerSourceInformation mappingElementWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(this.walkerSourceInformation.getSourceId(), lineOffset, columnOffset).withReturnSourceInfo(this.walkerSourceInformation.getReturnSourceInfo()).build();
MappingElementSourceCode mappingElementSourceCode = new MappingElementSourceCode(mappingInput, parserName, mappingElementWalkerSourceInformation, this.mappingElementSourceCode.mappingElementParserRuleContext, this.walkerSourceInformation);
Object mappingElement = extraParser.parse(mappingElementSourceCode, this.parserContext);
if (mappingElement instanceof ClassMapping) {
ClassMapping classMapping = (ClassMapping) mappingElement;
classMapping.id = classMapping.id == null ? mapping.id + "_Main" : classMapping.id + "_Main";
mapping.mainSetImplementation = classMapping;
if (classMapping instanceof PureInstanceClassMapping) {
mapping.propertyMappings = ListIterate.collect(((PureInstanceClassMapping) classMapping).propertyMappings, this::visitAggregationAwarePropertyMapping);
}
} else {
throw new EngineException("Invalid parser result for " + mappingElementSourceCode.name + ": " + mappingElement, this.walkerSourceInformation.getSourceInformation(ctx), EngineErrorType.PARSER);
}
}
Aggregations