Search in sources :

Example 1 with InlineDSLLibrary

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);
    }
}
Also used : PureException(org.finos.legend.pure.m4.exception.PureException) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport) TopParser(org.finos.legend.pure.m3.serialization.grammar.top.TopParser) M3ProcessorSupport(org.finos.legend.pure.m3.navigation.M3ProcessorSupport) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) InlineDSLLibrary(org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSLLibrary) PureCodeStorage(org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage) M3AntlrParser(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser) Parser(org.finos.legend.pure.m3.serialization.grammar.Parser) TopParser(org.finos.legend.pure.m3.serialization.grammar.top.TopParser)

Example 2 with InlineDSLLibrary

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);
    }
}
Also used : Matcher(org.finos.legend.pure.m3.tools.matcher.Matcher) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) MatchRunner(org.finos.legend.pure.m3.tools.matcher.MatchRunner) InlineDSL(org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSL) Parser(org.finos.legend.pure.m3.serialization.grammar.Parser)

Example 3 with InlineDSLLibrary

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);
}
Also used : ParserLibrary(org.finos.legend.pure.m3.serialization.grammar.ParserLibrary) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) InlineDSLLibrary(org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSLLibrary)

Example 4 with InlineDSLLibrary

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());
}
Also used : ParserLibrary(org.finos.legend.pure.m3.serialization.grammar.ParserLibrary) M3AntlrParser(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) VoidM4StateListener(org.finos.legend.pure.m4.statelistener.VoidM4StateListener) InlineDSLLibrary(org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSLLibrary) Test(org.junit.Test)

Example 5 with InlineDSLLibrary

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);
    });
}
Also used : Matcher(org.finos.legend.pure.m3.tools.matcher.Matcher) InlineDSL(org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSL) Parser(org.finos.legend.pure.m3.serialization.grammar.Parser)

Aggregations

CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)5 Parser (org.finos.legend.pure.m3.serialization.grammar.Parser)3 InlineDSLLibrary (org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSLLibrary)3 Matcher (org.finos.legend.pure.m3.tools.matcher.Matcher)3 ParserLibrary (org.finos.legend.pure.m3.serialization.grammar.ParserLibrary)2 M3AntlrParser (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3AntlrParser)2 InlineDSL (org.finos.legend.pure.m3.serialization.grammar.m3parser.inlinedsl.InlineDSL)2 FunctionDefinition (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.FunctionDefinition)1 PureExecutionException (org.finos.legend.pure.m3.exception.PureExecutionException)1 M3ProcessorSupport (org.finos.legend.pure.m3.navigation.M3ProcessorSupport)1 ProcessorSupport (org.finos.legend.pure.m3.navigation.ProcessorSupport)1 PureCodeStorage (org.finos.legend.pure.m3.serialization.filesystem.PureCodeStorage)1 TopParser (org.finos.legend.pure.m3.serialization.grammar.top.TopParser)1 MatchRunner (org.finos.legend.pure.m3.tools.matcher.MatchRunner)1 PureException (org.finos.legend.pure.m4.exception.PureException)1 VoidM4StateListener (org.finos.legend.pure.m4.statelistener.VoidM4StateListener)1 Test (org.junit.Test)1