Search in sources :

Example 1 with Section

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.Section in project legend-engine by finos.

the class PersistenceParserExtension method parseSection.

private static Section parseSection(SectionSourceCode sectionSourceCode, Consumer<PackageableElement> elementConsumer, PureGrammarParserContext context) {
    SourceCodeParserInfo parserInfo = getPersistenceParserInfo(sectionSourceCode);
    ImportAwareCodeSection section = new ImportAwareCodeSection();
    section.parserName = sectionSourceCode.sectionType;
    section.sourceInformation = parserInfo.sourceInformation;
    PersistenceParseTreeWalker walker = new PersistenceParseTreeWalker(parserInfo.walkerSourceInformation, elementConsumer, section);
    walker.visit((PersistenceParserGrammar.DefinitionContext) parserInfo.rootContext);
    return section;
}
Also used : SourceCodeParserInfo(org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo) ImportAwareCodeSection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection) PersistenceParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.PersistenceParserGrammar)

Example 2 with Section

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.Section in project legend-engine by finos.

the class DiagramParserExtension method parseSection.

private static Section parseSection(SectionSourceCode sectionSourceCode, Consumer<PackageableElement> elementConsumer, PureGrammarParserContext pureGrammarParserContext) {
    SourceCodeParserInfo parserInfo = getDiagramParserInfo(sectionSourceCode);
    ImportAwareCodeSection section = new ImportAwareCodeSection();
    section.parserName = sectionSourceCode.sectionType;
    section.sourceInformation = parserInfo.sourceInformation;
    DiagramParseTreeWalker walker = new DiagramParseTreeWalker(parserInfo.walkerSourceInformation, elementConsumer, section);
    walker.visit((DiagramParserGrammar.DefinitionContext) parserInfo.rootContext);
    return section;
}
Also used : SourceCodeParserInfo(org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo) ImportAwareCodeSection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection) DiagramParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.DiagramParserGrammar)

Example 3 with Section

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.Section in project legend-engine by finos.

the class TestModelToFlatDataGeneration method testSimpleCsv.

@Test
public void testSimpleCsv() {
    String modelCode = "Class test::gen::Data\n" + "{\n" + "  name        : String[1];\n" + "  employed    : Boolean[0..1];\n" + "  iq          : Integer[0..1];\n" + "  weightKg    : Float[0..1];\n" + "  heightM     : Decimal[1];\n" + "  dateOfBirth : StrictDate[1];\n" + "  timeOfDeath : DateTime[1];\n" + "}";
    PureModelContextData generated = generateSchema(modelCode, config("test::gen"));
    Binding binding = generated.getElementsOfType(Binding.class).stream().findFirst().get();
    Assert.assertEquals("test::gen::TestBinding", binding.getPath());
    Assert.assertEquals("test::gen::TestSchemaSet", binding.schemaSet);
    Assert.assertEquals(Collections.singletonList("test::gen::Data"), binding.modelUnit.packageableElementIncludes);
    ExternalFormatSchemaSet schemaSet = generated.getElementsOfType(ExternalFormatSchemaSet.class).stream().findFirst().get();
    String expectedDefiniiton = "section Data: DelimitedWithHeadings\n" + "{\n" + "  scope.untilEof;\n" + "  delimiter: ',';\n" + "\n" + "  Record\n" + "  {\n" + "    name: STRING;\n" + "    employed: BOOLEAN(optional);\n" + "    iq: INTEGER(optional);\n" + "    weightKg: DECIMAL(optional);\n" + "    heightM: DECIMAL;\n" + "    dateOfBirth: DATE;\n" + "    timeOfDeath: DATETIME;\n" + "  }\n" + "}";
    Assert.assertEquals(expectedDefiniiton, schemaSet.schemas.get(0).content);
}
Also used : Binding(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.Binding) ExternalFormatSchemaSet(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatSchemaSet) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) ModelToSchemaGenerationTest(org.finos.legend.engine.external.shared.format.model.test.ModelToSchemaGenerationTest) Test(org.junit.Test)

Example 4 with Section

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.Section in project legend-engine by finos.

the class TestFlatDataToModelGeneration method testSimpleCsvWithPurifiedNames.

@Test
public void testSimpleCsvWithPurifiedNames() {
    String schemaCode = newExternalSchemaSetGrammarBuilder("test::Simple", "FlatData").withSchemaText("section data: DelimitedWithHeadings\n" + "{\n" + "  scope.untilEof;\n" + "  delimiter: ',';\n" + "\n" + "  Record\n" + "  {\n" + "    Name            : STRING;\n" + "    Employed        : INTEGER(optional);\n" + "    IQ              : INTEGER(optional);\n" + "    'Weight KG'     : DECIMAL(optional);\n" + "    'DATE OF BIRTH' : DATE;\n" + "    TIME_OF_DEATH   : DATETIME;\n" + "  }\n" + "}").build();
    PureModelContextData model = generateModel(schemaCode, config("test::Simple", "test::gen", true));
    String expected = ">>>test::gen::DataRecord\n" + "Class test::gen::DataRecord extends meta::pure::metamodel::type::Any\n" + "{\n" + "  name: String[1];\n" + "  employed: Integer[0..1];\n" + "  iq: Integer[0..1];\n" + "  weightKg: Float[0..1];\n" + "  dateOfBirth: StrictDate[1];\n" + "  timeOfDeath: DateTime[1];\n" + "}";
    Assert.assertEquals(modelTextsFromString(expected), modelTextsFromContextData(model));
}
Also used : PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Test(org.junit.Test) SchemaToModelGenerationTest(org.finos.legend.engine.external.shared.format.model.test.SchemaToModelGenerationTest)

Example 5 with Section

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.Section in project legend-engine by finos.

the class RuntimeParser method parse.

@Override
public Section parse(SourceCodeParserInfo sectionParserInfo, Consumer<PackageableElement> pureModelContextData, PureGrammarParserContext parserContext) {
    ImportAwareCodeSection section = new ImportAwareCodeSection();
    section.parserName = this.getName();
    section.sourceInformation = sectionParserInfo.sourceInformation;
    RuntimeParseTreeWalker walker = new RuntimeParseTreeWalker(sectionParserInfo.walkerSourceInformation, pureModelContextData, section, this.connectionParser);
    walker.visit((RuntimeParserGrammar.DefinitionContext) sectionParserInfo.rootContext);
    return section;
}
Also used : ImportAwareCodeSection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection) RuntimeParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.runtime.RuntimeParserGrammar)

Aggregations

ImportAwareCodeSection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection)11 SourceCodeParserInfo (org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo)6 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)6 DefaultCodeSection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.DefaultCodeSection)5 Test (org.junit.Test)5 SchemaToModelGenerationTest (org.finos.legend.engine.external.shared.format.model.test.SchemaToModelGenerationTest)4 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)3 ListIterate (org.eclipse.collections.impl.utility.ListIterate)2 ModelToSchemaGenerationTest (org.finos.legend.engine.external.shared.format.model.test.ModelToSchemaGenerationTest)2 CodeParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.CodeParserGrammar)2 SectionParser (org.finos.legend.engine.language.pure.grammar.from.extension.SectionParser)2 SourceInformation (org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)2 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)2 Section (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.Section)2 SectionIndex (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex)2 LogInfo (org.finos.legend.engine.shared.core.operational.logs.LogInfo)2 List (java.util.List)1 Consumer (java.util.function.Consumer)1 CharStreams (org.antlr.v4.runtime.CharStreams)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1