diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/connection/ConnectionParseTreeWalker.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/connection/ConnectionParseTreeWalker.java index 441ca2efcec..94c1531afd8 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/connection/ConnectionParseTreeWalker.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/connection/ConnectionParseTreeWalker.java @@ -16,6 +16,7 @@ import org.eclipse.collections.impl.utility.ListIterate; import org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation; +import org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserContext; import org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserUtility; import org.finos.legend.engine.language.pure.grammar.from.antlr4.connection.ConnectionParserGrammar; import org.finos.legend.engine.language.pure.grammar.from.extension.ConnectionValueParser; @@ -94,7 +95,7 @@ private Connection visitConnectionValue(ConnectionParserGrammar.ConnectionValueC // only add current walker source information column offset if this is the first line int columnOffset = (startLine == 1 ? walkerSourceInformation.getColumnOffset() : 0) + ctx.BRACE_OPEN().getSymbol().getCharPositionInLine() + ctx.BRACE_OPEN().getSymbol().getText().length(); ParseTreeWalkerSourceInformation connectionValueWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(walkerSourceInformation.getSourceId(), lineOffset, columnOffset).withReturnSourceInfo(this.walkerSourceInformation.getReturnSourceInfo()).build(); - ConnectionValueSourceCode connectionValueSourceCode = new ConnectionValueSourceCode(connectionValueCode, connectionType, sourceInformation, connectionValueWalkerSourceInformation, isProcessingEmbeddedConnection); + ConnectionValueSourceCode connectionValueSourceCode = new ConnectionValueSourceCode(connectionValueCode, connectionType, sourceInformation, connectionValueWalkerSourceInformation, isProcessingEmbeddedConnection, new PureGrammarParserContext(this.extensions)); ConnectionValueParser connectionValueParser = this.extensions.getConnectionValueParser(connectionType); if (connectionValueParser == null) { diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/connection/ConnectionValueSourceCode.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/connection/ConnectionValueSourceCode.java index 466e4e8e845..2bd6bbe7c99 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/connection/ConnectionValueSourceCode.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/connection/ConnectionValueSourceCode.java @@ -15,6 +15,7 @@ package org.finos.legend.engine.language.pure.grammar.from.connection; import org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation; +import org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserContext; import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; public class ConnectionValueSourceCode @@ -24,13 +25,15 @@ public class ConnectionValueSourceCode public final SourceInformation sourceInformation; public final ParseTreeWalkerSourceInformation walkerSourceInformation; public final boolean isEmbedded; + public final PureGrammarParserContext context; - public ConnectionValueSourceCode(String code, String connectionType, SourceInformation sourceInformation, ParseTreeWalkerSourceInformation walkerSourceInformation, boolean isEmbedded) + public ConnectionValueSourceCode(String code, String connectionType, SourceInformation sourceInformation, ParseTreeWalkerSourceInformation walkerSourceInformation, boolean isEmbedded, PureGrammarParserContext context) { this.code = code; this.connectionType = connectionType; this.sourceInformation = sourceInformation; this.walkerSourceInformation = walkerSourceInformation; this.isEmbedded = isEmbedded; + this.context = context; } } diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/extension/PureGrammarParserExtensions.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/extension/PureGrammarParserExtensions.java index 8a7b84e657b..7114a64ec04 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/extension/PureGrammarParserExtensions.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/extension/PureGrammarParserExtensions.java @@ -62,6 +62,11 @@ public List getExtensions() return this.extensions.castToList(); } + public List getExtensionsOfType(Class ofType) + { + return this.extensions.selectInstancesOf(ofType).castToList(); + } + public SectionParser getExtraSectionParser(String type) { return this.sectionParsers.get(type); diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/IRelationalGrammarParserExtension.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/IRelationalGrammarParserExtension.java index 868ea6cdc6f..6a15375c6d9 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/IRelationalGrammarParserExtension.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/IRelationalGrammarParserExtension.java @@ -43,9 +43,9 @@ public interface IRelationalGrammarParserExtension extends PureGrammarParserExtension { - static List getExtensions() + static List getExtensions(PureGrammarParserContext context) { - return Lists.mutable.withAll(ServiceLoader.load(IRelationalGrammarParserExtension.class)); + return context.getPureGrammarParserExtensions().getExtensionsOfType(IRelationalGrammarParserExtension.class); } static DatasourceSpecification process(DataSourceSpecificationSourceCode code, List> processors) diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/RelationalDatabaseConnectionParseTreeWalker.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/RelationalDatabaseConnectionParseTreeWalker.java index 848debb5114..3f935a03fcb 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/RelationalDatabaseConnectionParseTreeWalker.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/RelationalDatabaseConnectionParseTreeWalker.java @@ -35,9 +35,11 @@ public class RelationalDatabaseConnectionParseTreeWalker { private final ParseTreeWalkerSourceInformation walkerSourceInformation; + private final PureGrammarParserContext context; - public RelationalDatabaseConnectionParseTreeWalker(ParseTreeWalkerSourceInformation walkerSourceInformation) + public RelationalDatabaseConnectionParseTreeWalker(PureGrammarParserContext context, ParseTreeWalkerSourceInformation walkerSourceInformation) { + this.context = context; this.walkerSourceInformation = walkerSourceInformation; } @@ -91,7 +93,7 @@ public void visitRelationalDatabaseConnectionValue(RelationalDatabaseConnectionP private void handleLocalMode(RelationalDatabaseConnection connectionValue) { connectionValue.localMode = true; - List extensions = IRelationalGrammarParserExtension.getExtensions(); + List extensions = IRelationalGrammarParserExtension.getExtensions(context); try { connectionValue.datasourceSpecification = IRelationalGrammarParserExtension.process( @@ -111,7 +113,7 @@ private void handleLocalMode(RelationalDatabaseConnection connectionValue) private List visitRelationalPostProcessors(RelationalDatabaseConnectionParserGrammar.RelationalPostProcessorsContext postProcessorsContext) { List specifications = postProcessorsContext.specification(); - List extensions = IRelationalGrammarParserExtension.getExtensions(); + List extensions = IRelationalGrammarParserExtension.getExtensions(context); List> parsers = ListIterate.flatCollect(extensions, IRelationalGrammarParserExtension::getExtraPostProcessorParsers); return ListIterate.collect(specifications, spec -> visitRelationalPostProcessor(spec, parsers)); } @@ -149,7 +151,7 @@ private DatasourceSpecification visitRelationalDatabaseConnectionDatasourceSpeci ParseTreeWalkerSourceInformation.offset(walkerSourceInformation, ctx.getStart()) ); - List extensions = IRelationalGrammarParserExtension.getExtensions(); + List extensions = IRelationalGrammarParserExtension.getExtensions(context); DatasourceSpecification ds = IRelationalGrammarParserExtension.process(code, ListIterate.flatCollect(extensions, IRelationalGrammarParserExtension::getExtraDataSourceSpecificationParsers)); if (ds == null) @@ -173,7 +175,7 @@ public AuthenticationStrategy visitRelationalDatabaseConnectionAuthenticationStr ParseTreeWalkerSourceInformation.offset(walkerSourceInformation, ctx.getStart()) ); - List extensions = IRelationalGrammarParserExtension.getExtensions(); + List extensions = IRelationalGrammarParserExtension.getExtensions(context); AuthenticationStrategy auth = IRelationalGrammarParserExtension.process(code, ListIterate.flatCollect(extensions, IRelationalGrammarParserExtension::getExtraAuthenticationStrategyParsers)); if (auth == null) diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/RelationalGrammarParserExtension.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/RelationalGrammarParserExtension.java index a2a0eb9846a..55f9b6dbebe 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/RelationalGrammarParserExtension.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/RelationalGrammarParserExtension.java @@ -30,20 +30,20 @@ import org.finos.legend.engine.language.pure.grammar.from.antlr4.connection.authentication.AuthenticationStrategyParserGrammar; import org.finos.legend.engine.language.pure.grammar.from.antlr4.connection.datasource.DataSourceSpecificationLexerGrammar; import org.finos.legend.engine.language.pure.grammar.from.antlr4.connection.datasource.DataSourceSpecificationParserGrammar; -import org.finos.legend.engine.language.pure.grammar.from.antlr4.data.DataParserGrammar; import org.finos.legend.engine.language.pure.grammar.from.antlr4.mapper.RelationalMapperLexerGrammar; import org.finos.legend.engine.language.pure.grammar.from.antlr4.mapper.RelationalMapperParserGrammar; import org.finos.legend.engine.language.pure.grammar.from.antlr4.mapping.MappingParserGrammar; import org.finos.legend.engine.language.pure.grammar.from.authentication.AuthenticationStrategyParseTreeWalker; import org.finos.legend.engine.language.pure.grammar.from.authentication.AuthenticationStrategySourceCode; import org.finos.legend.engine.language.pure.grammar.from.connection.ConnectionValueSourceCode; -import org.finos.legend.engine.language.pure.grammar.from.data.DataParseTreeWalker; import org.finos.legend.engine.language.pure.grammar.from.data.RelationalEmbeddedDataParser; import org.finos.legend.engine.language.pure.grammar.from.datasource.DataSourceSpecificationParseTreeWalker; import org.finos.legend.engine.language.pure.grammar.from.datasource.DataSourceSpecificationSourceCode; import org.finos.legend.engine.language.pure.grammar.from.extension.ConnectionValueParser; import org.finos.legend.engine.language.pure.grammar.from.extension.MappingElementParser; import org.finos.legend.engine.language.pure.grammar.from.extension.MappingTestInputDataParser; +import org.finos.legend.engine.language.pure.grammar.from.extension.PureGrammarParserExtensionLoader; +import org.finos.legend.engine.language.pure.grammar.from.extension.PureGrammarParserExtensions; import org.finos.legend.engine.language.pure.grammar.from.extension.SectionParser; import org.finos.legend.engine.language.pure.grammar.from.extension.data.EmbeddedDataParser; import org.finos.legend.engine.language.pure.grammar.from.mapper.RelationalMapperParseTreeWalker; @@ -108,7 +108,7 @@ private static Section parseRelationalSection(SectionSourceCode sectionSourceCod DefaultCodeSection section = new DefaultCodeSection(); section.parserName = sectionSourceCode.sectionType; section.sourceInformation = parserInfo.sourceInformation; - RelationalParseTreeWalker walker = new RelationalParseTreeWalker(parserInfo.walkerSourceInformation, elementConsumer, section); + RelationalParseTreeWalker walker = new RelationalParseTreeWalker(parserInfo.walkerSourceInformation, elementConsumer, section, pureGrammarParserContext); walker.visit((RelationalParserGrammar.DefinitionContext) parserInfo.rootContext); return section; } @@ -147,7 +147,7 @@ public Iterable getExtraMappingElementParsers() { MappingParserGrammar.MappingElementContext ctx = mappingElementSourceCode.mappingElementParserRuleContext; SourceCodeParserInfo parserInfo = getRelationalMappingElementParserInfo(mappingElementSourceCode); - RelationalParseTreeWalker walker = new RelationalParseTreeWalker(parserInfo.walkerSourceInformation); + RelationalParseTreeWalker walker = new RelationalParseTreeWalker(parserInfo.walkerSourceInformation, parserContext); if (parserInfo.rootContext instanceof RelationalParserGrammar.ClassMappingContext) { RootRelationalClassMapping classMapping = new RootRelationalClassMapping(); @@ -182,7 +182,7 @@ public Iterable getExtraConnectionParsers() return Collections.singletonList(ConnectionValueParser.newParser(RELATIONAL_DATABASE_CONNECTION_TYPE, connectionValueSourceCode -> { SourceCodeParserInfo parserInfo = getRelationalDatabaseConnectionParserInfo(connectionValueSourceCode); - RelationalDatabaseConnectionParseTreeWalker walker = new RelationalDatabaseConnectionParseTreeWalker(parserInfo.walkerSourceInformation); + RelationalDatabaseConnectionParseTreeWalker walker = new RelationalDatabaseConnectionParseTreeWalker(connectionValueSourceCode.context, parserInfo.walkerSourceInformation); RelationalDatabaseConnection connectionValue = new RelationalDatabaseConnection(); connectionValue.sourceInformation = connectionValueSourceCode.sourceInformation; walker.visitRelationalDatabaseConnectionValue((RelationalDatabaseConnectionParserGrammar.DefinitionContext) parserInfo.rootContext, connectionValue, connectionValueSourceCode.isEmbedded); @@ -411,21 +411,6 @@ private static SourceCodeParserInfo getRelationalDatabaseConnectionParserInfo(Co return new SourceCodeParserInfo(connectionValueSourceCode.code, input, connectionValueSourceCode.sourceInformation, connectionValueSourceCode.walkerSourceInformation, lexer, parser, parser.definition()); } - public static RelationalOperationElement parseRelationalOperationElement(String code, String sourceId, int lineOffset, int columnOffset, boolean returnSourceInfo) - { - CharStream input = CharStreams.fromString(code); - ParseTreeWalkerSourceInformation parseTreeWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(sourceId, lineOffset, columnOffset).withReturnSourceInfo(returnSourceInfo).build(); - ParserErrorListener errorListener = new ParserErrorListener(parseTreeWalkerSourceInformation); - RelationalLexerGrammar lexer = new RelationalLexerGrammar(input); - lexer.removeErrorListeners(); - lexer.addErrorListener(errorListener); - RelationalParserGrammar parser = new RelationalParserGrammar(new CommonTokenStream(lexer)); - parser.removeErrorListeners(); - parser.addErrorListener(errorListener); - RelationalParseTreeWalker walker = new RelationalParseTreeWalker(parseTreeWalkerSourceInformation); - return walker.visitOperation(parser.operation(), null); - } - public static void propagateStorePath(RelationalAssociationMapping mapping) { RelationalPropertyMapping propertyMapping = (RelationalPropertyMapping) mapping.propertyMappings.stream() @@ -443,4 +428,19 @@ public static void propagateStorePath(RelationalAssociationMapping mapping) } } } + + public static RelationalOperationElement parseRelationalOperationElement(String code, String sourceId, int lineOffset, int columnOffset, boolean returnSourceInfo) + { + CharStream input = CharStreams.fromString(code); + ParseTreeWalkerSourceInformation parseTreeWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(sourceId, lineOffset, columnOffset).withReturnSourceInfo(returnSourceInfo).build(); + ParserErrorListener errorListener = new ParserErrorListener(parseTreeWalkerSourceInformation); + RelationalLexerGrammar lexer = new RelationalLexerGrammar(input); + lexer.removeErrorListeners(); + lexer.addErrorListener(errorListener); + RelationalParserGrammar parser = new RelationalParserGrammar(new CommonTokenStream(lexer)); + parser.removeErrorListeners(); + parser.addErrorListener(errorListener); + RelationalParseTreeWalker walker = new RelationalParseTreeWalker(parseTreeWalkerSourceInformation, new PureGrammarParserContext(PureGrammarParserExtensions.fromExtensions(PureGrammarParserExtensionLoader.extensions()))); + return walker.visitOperation(parser.operation(), null); + } } diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/RelationalParseTreeWalker.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/RelationalParseTreeWalker.java index d5d05a90d36..a1f76251ead 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/RelationalParseTreeWalker.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/grammar/from/RelationalParseTreeWalker.java @@ -95,17 +95,19 @@ public class RelationalParseTreeWalker private final DefaultCodeSection section; private static final ImmutableSet JOIN_TYPES = Sets.immutable.with("INNER", "OUTER"); + private final PureGrammarParserContext context; - public RelationalParseTreeWalker(ParseTreeWalkerSourceInformation walkerSourceInformation) + public RelationalParseTreeWalker(ParseTreeWalkerSourceInformation walkerSourceInformation, PureGrammarParserContext context) { - this(walkerSourceInformation, null, null); + this(walkerSourceInformation, null, null, context); } - public RelationalParseTreeWalker(ParseTreeWalkerSourceInformation walkerSourceInformation, Consumer elementConsumer, DefaultCodeSection section) + public RelationalParseTreeWalker(ParseTreeWalkerSourceInformation walkerSourceInformation, Consumer elementConsumer, DefaultCodeSection section, PureGrammarParserContext context) { this.walkerSourceInformation = walkerSourceInformation; this.elementConsumer = elementConsumer; this.section = section; + this.context = context; } public void visit(RelationalParserGrammar.DefinitionContext ctx) @@ -464,7 +466,7 @@ private Milestoning visitMilestoning(RelationalParserGrammar.MilestoningContext ParseTreeWalkerSourceInformation.offset(walkerSourceInformation, ctx.getStart()) ); - List extensions = IRelationalGrammarParserExtension.getExtensions(); + List extensions = IRelationalGrammarParserExtension.getExtensions(context); Milestoning milestoning = IRelationalGrammarParserExtension.process(code, ListIterate.flatCollect(extensions, IRelationalGrammarParserExtension::getExtraMilestoningParsers)); if (milestoning == null)