use of org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSLLibrary in project legend-pure by finos.
the class Loader method parseM3.
public static void parseM3(String code, ModelRepository repository, ParserLibrary library, ValidationType validationType, M3M4StateListener stateListener, Context context) {
try {
ListMultimap<Parser, CoreInstance> newInstancesByParser = new TopParser().parse(code, "fromString.pure", repository, library, stateListener, context, null);
ListIterable<CoreInstance> newInstances = newInstancesByParser.valuesView().toList();
updateStateFullContextCache(newInstances, context);
ProcessorSupport processorSupport = new M3ProcessorSupport(context, repository);
PostProcessor.process(newInstances, repository, library, new InlineDSLLibrary(), null, context, processorSupport, null, null);
processExcludes(repository, processorSupport, stateListener);
if (validationType == ValidationType.DEEP) {
repository.validate(stateListener);
}
// Validate M3
stateListener.startValidation();
Validator.validateM3(newInstances, validationType, library, new InlineDSLLibrary(), new PureCodeStorage(null), repository, context, processorSupport);
stateListener.finishedValidation();
} catch (PureException exception) {
String space = " ";
throw new RuntimeException(exception + " in\n" + space + code.replace("\n", "\n" + space), exception);
}
}
use of org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSLLibrary in project legend-pure by finos.
the class Validator method validateM3.
public static void validateM3(Iterable<? extends CoreInstance> newInstancesConsolidated, ValidationType validationType, ParserLibrary parserLibrary, InlineDSLLibrary inlineDSLLibrary, Iterable<? extends MatchRunner> additionalValidators, CodeStorage codeStorage, ModelRepository modelRepository, Context context, ProcessorSupport processorSupport) throws PureCompilationException {
// Post Process
Matcher matcher = new Matcher(modelRepository, context, processorSupport);
for (Parser parser : parserLibrary.getParsers()) {
for (MatchRunner parserValidator : parser.getValidators()) {
matcher.addMatchIfTypeIsKnown(parserValidator);
}
}
for (InlineDSL dsl : inlineDSLLibrary.getInlineDSLs()) {
for (MatchRunner dslValidator : dsl.getValidators()) {
matcher.addMatchIfTypeIsKnown(dslValidator);
}
}
for (MatchRunner validator : additionalValidators) {
matcher.addMatchIfTypeIsKnown(validator);
}
ValidatorState validatorState = new ValidatorState(validationType, codeStorage, processorSupport);
for (CoreInstance instance : newInstancesConsolidated) {
validate(instance, validatorState, matcher, processorSupport);
}
}
use of org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSLLibrary in project legend-pure by finos.
the class NewAssociation method execute.
@Override
public CoreInstance execute(ListIterable<? extends CoreInstance> params, Stack<MutableMap<String, CoreInstance>> resolvedTypeParameters, Stack<MutableMap<String, CoreInstance>> resolvedMultiplicityParameters, VariableContext variableContext, CoreInstance functionExpressionToUseInStack, Profiler profiler, InstantiationContext instantiationContext, ExecutionSupport executionSupport, Context context, ProcessorSupport processorSupport) {
String fullPathString = PrimitiveUtilities.getStringValue(Instance.getValueForMetaPropertyToOneResolved(params.getFirst(), M3Properties.values, processorSupport));
ListIterable<String> fullPath = PackageableElement.splitUserPath(fullPathString);
if (fullPath.isEmpty()) {
throw new PureExecutionException(functionExpressionToUseInStack.getSourceInformation(), "Cannot create a new Association: '" + fullPathString + "'");
}
String name = fullPath.getLast();
CoreInstance pack = _Package.findOrCreatePackageFromUserPath(ListHelper.subList(fullPath, 0, fullPath.size() - 1), this.repository, processorSupport);
CoreInstance newAssociation = this.repository.newCoreInstance(name, processorSupport.package_getByUserPath(M3Paths.Association), null);
Instance.addValueToProperty(newAssociation, M3Properties.name, this.repository.newCoreInstance(name, this.repository.getTopLevel(M3Paths.String), null), processorSupport);
Instance.addValueToProperty(newAssociation, M3Properties.properties, Instance.getValueForMetaPropertyToOneResolved(params.get(1), M3Properties.values, processorSupport), processorSupport);
Instance.addValueToProperty(newAssociation, M3Properties.properties, Instance.getValueForMetaPropertyToOneResolved(params.get(2), M3Properties.values, processorSupport), processorSupport);
PostProcessor.process(Lists.immutable.with(newAssociation), this.repository, new ParserLibrary(), new InlineDSLLibrary(), null, context, processorSupport, null, null);
Instance.addValueToProperty(newAssociation, M3Properties._package, pack, processorSupport);
Instance.addValueToProperty(pack, M3Properties.children, newAssociation, processorSupport);
return ValueSpecificationBootstrap.wrapValueSpecification(newAssociation, true, processorSupport);
}
use of org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSLLibrary in project legend-pure by finos.
the class TestLineInfo method testLineInfoForStaticInstanceGeneratedM3.
@Test
public void testLineInfoForStaticInstanceGeneratedM3() throws Exception {
MutableList<CoreInstance> parsed = Lists.mutable.with();
new M3AntlrParser().parse("Class Person\n" + "{\n" + " lastName:String[1];\n" + "}\n" + "^Person p ?[a/b/c/file.txt:1,3,2,2,4,5]? (lastName='last')\n", "fromString.pure", false, 0, this.repository, parsed, VoidM3M4StateListener.VOID_M3_M4_STATE_LISTENER, this.context, 1, null);
this.repository.validate(new VoidM4StateListener());
PostProcessor.process(parsed, this.repository, new ParserLibrary(), new InlineDSLLibrary(), null, this.context, this.processorSupport, null, null);
Validator.validateM3(parsed, ValidationType.DEEP, new ParserLibrary(), new InlineDSLLibrary(), this.runtime.getCodeStorage(), this.repository, this.context, this.processorSupport);
CoreInstance p = this.runtime.getCoreInstance("p");
Assert.assertNotNull(p);
assertSourceInformation("a/b/c/file.txt", 1, 3, 2, 2, 4, 5, p.getSourceInformation());
CoreInstance person = this.runtime.getCoreInstance("Person");
Assert.assertNotNull(person);
// Person doesn't have debug info because we use 'false' for addLines in the parse method!
Assert.assertNull(person.getSourceInformation());
}
use of org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSLLibrary in project legend-pure by finos.
the class Unbinder method process.
public static void process(SetIterable<? extends CoreInstance> consolidatedCoreInstances, ModelRepository modelRepository, ParserLibrary library, InlineDSLLibrary dslLibrary, Context context, ProcessorSupport processorSupport, UnbindState state, Message message) {
Matcher unbindMatcher = new Matcher(modelRepository, context, processorSupport);
library.getParsers().asLazy().flatCollect(Parser::getUnLoadUnbinders).concatenate(dslLibrary.getInlineDSLs().asLazy().flatCollect(InlineDSL::getUnLoadUnbinders)).forEach(unbindMatcher::addMatchIfTypeIsKnown);
Runnable messageRunnable;
if (message == null) {
messageRunnable = () -> {
};
} else {
int[] messageCount = { 0 };
String suffix = "/" + consolidatedCoreInstances.size() + ")";
messageRunnable = () -> message.setMessage("Unbinding (" + messageCount[0]++ + suffix);
}
consolidatedCoreInstances.forEach(instance -> {
messageRunnable.run();
unbindMatcher.match(instance, state);
context.update(instance);
});
}
Aggregations