From 795b99c26170bc6cfbd62710e3c74c86f1f6250d Mon Sep 17 00:00:00 2001 From: maytheu Date: Mon, 11 Sep 2023 16:11:42 +0100 Subject: [PATCH 01/12] initial formatter schema --- ...rsal-data-definition-language-formatter.ts | 33 ++++++++++++++++--- ...data-definition-language-formatter.test.ts | 2 +- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/language-server/universal-data-definition-language-formatter.ts b/src/language-server/universal-data-definition-language-formatter.ts index 9bf0734..2ebf53e 100644 --- a/src/language-server/universal-data-definition-language-formatter.ts +++ b/src/language-server/universal-data-definition-language-formatter.ts @@ -64,7 +64,7 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter this.formatLogicalDataModel(dm) }) ldm.element.forEach( elem => { - this.formatElement(elem) + this.formatLogicalElement(elem) }) } @@ -74,7 +74,7 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter this.formatPlatfornDataModel(dm) }) pdm.element.forEach(elem => { - this.formatElement(elem) + this.formatPlatformElement(elem) }) } @@ -84,7 +84,31 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter this.formatObj(elem); } - protected formatElement(elem: ast.LogicalElement | ast.PlatformElement): void { + protected formatConceptualEntity(entity: ast.ConceptualEntity): void { + this.formatContainer(entity) + entity.basisEntity.forEach(basis => { + + }) + entity.composition.forEach(comp => { + this.formatConceptualComposition(comp) + }) + } + + protected formatConceptualAssociation(assoc: ast.ConceptualAssociation): void {} + + protected formatConceptualCharacteristic(xter: ast.ConceptualCharacteristic): void {} + + protected formatConceptualComposition(comp: ast.ConceptualComposition ): void {} + + protected formatConceptualParticipant(participant: ast.ConceptualParticipant): void {} + + protected formatLogicalElement(elem: ast.LogicalElement): void { + const formatter = this.getNodeFormatter(elem); + formatter.property('name').prepend(Formatting.newLine()).surround(Formatting.oneSpace({allowMore: true})); + this.formatObj(elem); + } + + protected formatPlatformElement(elem: ast.PlatformElement): void { const formatter = this.getNodeFormatter(elem); formatter.property('name').prepend(Formatting.newLine()).surround(Formatting.oneSpace({allowMore: true})); this.formatObj(elem); @@ -97,5 +121,4 @@ export const UniversalDataDefinitionLanguageModule: Module new UniversalDataDefinitionLanguageFormatter() } -}; - +}; \ No newline at end of file diff --git a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts index 4bf07ab..3c1dbb2 100644 --- a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts +++ b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts @@ -22,4 +22,4 @@ describe("Universal Data Definition Language Formatter", () => { }` }); }); -}); +}); \ No newline at end of file From a4d238e7cc7ab9a3eaaf3f8bf1969a88f270ee61 Mon Sep 17 00:00:00 2001 From: maytheu Date: Tue, 12 Sep 2023 21:25:40 +0100 Subject: [PATCH 02/12] conceptual entity formatter --- ...rsal-data-definition-language-formatter.ts | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/language-server/universal-data-definition-language-formatter.ts b/src/language-server/universal-data-definition-language-formatter.ts index 2ebf53e..ed6686a 100644 --- a/src/language-server/universal-data-definition-language-formatter.ts +++ b/src/language-server/universal-data-definition-language-formatter.ts @@ -1,4 +1,4 @@ -import { AbstractFormatter, AstNode, Formatting, Module, PartialLangiumServices } from 'langium'; +import { AbstractFormatter, AstNode, Formatting, Module, PartialLangiumServices, Reference } from 'langium'; import * as ast from './generated/ast'; import { UniversalDataDefinitionLanguageServices } from './universal-data-definition-language-module'; @@ -86,21 +86,40 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter protected formatConceptualEntity(entity: ast.ConceptualEntity): void { this.formatContainer(entity) + if(entity?.specializes){ + this.formatConceptualEntity(entity) + } entity.basisEntity.forEach(basis => { - + this.formatConceptualBasisEntity(basis) }) entity.composition.forEach(comp => { this.formatConceptualComposition(comp) }) } + protected formatConceptualBasisEntity(basisRef: Reference): void { + const formatter = this.getNodeFormatter(basisRef.ref!); + formatter.property('name').prepend(Formatting.newLine()).surround(Formatting.oneSpace({allowMore: true})); + console.log(basisRef); + + this.formatObj(basisRef.ref!); +} + protected formatConceptualAssociation(assoc: ast.ConceptualAssociation): void {} protected formatConceptualCharacteristic(xter: ast.ConceptualCharacteristic): void {} - protected formatConceptualComposition(comp: ast.ConceptualComposition ): void {} + protected formatConceptualComposition(comp: ast.ConceptualComposition ): void { + this.formatContainer(comp) + } - protected formatConceptualParticipant(participant: ast.ConceptualParticipant): void {} + protected formatConceptualParticipant(participant: ast.ConceptualParticipant): void { + this.formatContainer(participant) + + if(participant?.type){ + this.formatConceptualEntity(participant.type.ref!) + } + } protected formatLogicalElement(elem: ast.LogicalElement): void { const formatter = this.getNodeFormatter(elem); From 45174141eaade87b48284652fa9681accef9a0bf Mon Sep 17 00:00:00 2001 From: maytheu Date: Thu, 14 Sep 2023 20:34:39 +0100 Subject: [PATCH 03/12] formatter for conceptual element --- ...rsal-data-definition-language-formatter.ts | 47 +++++++++++-------- ...data-definition-language-formatter.test.ts | 31 +++++++++++- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/language-server/universal-data-definition-language-formatter.ts b/src/language-server/universal-data-definition-language-formatter.ts index ed6686a..86896e1 100644 --- a/src/language-server/universal-data-definition-language-formatter.ts +++ b/src/language-server/universal-data-definition-language-formatter.ts @@ -1,9 +1,8 @@ -import { AbstractFormatter, AstNode, Formatting, Module, PartialLangiumServices, Reference } from 'langium'; +import { AbstractFormatter, AstNode, Formatting, Module, PartialLangiumServices, } from 'langium'; import * as ast from './generated/ast'; import { UniversalDataDefinitionLanguageServices } from './universal-data-definition-language-module'; export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter { - protected formatContainer(node: AstNode): void { const formatter = this.getNodeFormatter(node); const open = formatter.keyword('{'); @@ -22,11 +21,21 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter close.surround(Formatting.noSpace()).prepend(Formatting.newLine({allowMore: true})).append(Formatting.newLine({allowMore: true})); } - protected format(node: AstNode): void { + protected format(node: AstNode): void { // This method is called for every AstNode in a document if (ast.isDataModel(node)) { this.formatDataModel(node); + } + if(ast.isConceptualAssociation(node)){ + this.formatConceptualAssociation(node) + } + if(ast.isConceptualEntity(node)){ + this.formatConceptualEntity(node) + } + + if(ast.isConceptualBasisEntity(node)){ + this.formatConceptualBasisEntity(node) } } @@ -50,10 +59,10 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter protected formatConceptualDataModel(cdm: ast.ConceptualDataModel): void { this.formatContainer(cdm); - cdm.cdm.forEach(dm => { + cdm.cdm.forEach(dm => { this.formatConceptualDataModel(dm); }) - cdm.element.forEach( elem => { + cdm.element.forEach( elem => { this.formatConceptualElement(elem); }) } @@ -78,34 +87,32 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter }) } - protected formatConceptualElement(elem: ast.ConceptualElement): void { + /**Formatting conceptuals */ + protected formatConceptualElement(elem: ast.ConceptualElement): void { const formatter = this.getNodeFormatter(elem); - formatter.property('name').prepend(Formatting.newLine()).surround(Formatting.oneSpace({allowMore: true})); + formatter.property('name').prepend(Formatting.newLine({allowMore: true})).surround(Formatting.oneSpace({allowMore: true})); this.formatObj(elem); } protected formatConceptualEntity(entity: ast.ConceptualEntity): void { this.formatContainer(entity) - if(entity?.specializes){ - this.formatConceptualEntity(entity) - } - entity.basisEntity.forEach(basis => { - this.formatConceptualBasisEntity(basis) - }) entity.composition.forEach(comp => { this.formatConceptualComposition(comp) }) } - protected formatConceptualBasisEntity(basisRef: Reference): void { - const formatter = this.getNodeFormatter(basisRef.ref!); + protected formatConceptualBasisEntity(basis: ast.ConceptualBasisEntity): void { + const formatter = this.getNodeFormatter(basis); formatter.property('name').prepend(Formatting.newLine()).surround(Formatting.oneSpace({allowMore: true})); - console.log(basisRef); - - this.formatObj(basisRef.ref!); -} + } + + protected formatConceptualAssociation(cassoc: ast.ConceptualAssociation): void { + this.formatContainer(cassoc) - protected formatConceptualAssociation(assoc: ast.ConceptualAssociation): void {} + cassoc.composition.forEach(comp => { + this.formatConceptualComposition(comp) + }) + } protected formatConceptualCharacteristic(xter: ast.ConceptualCharacteristic): void {} diff --git a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts index 3c1dbb2..f85631e 100644 --- a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts +++ b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts @@ -7,16 +7,43 @@ const universalDataDefinitionLanguageFormatting = expectFormatting(universalData ); describe("Universal Data Definition Language Formatter", () => { - it("should indent correctly", async () => { + it("should format cdm ", async () => { await universalDataDefinitionLanguageFormatting({ before: - 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{}}', + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis ee;}}', after: `dm PPT "Base data structures to support People, Places and Things" { cdm Conceptual "Need to start at Conceptual Level" { + basis ee ; + } + +}` + }); + }); + + it("should format concptual element", async () => { + await universalDataDefinitionLanguageFormatting({ + before: + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cassoc Training "Information delivered over time from one party to another " {};centity AddressableEntity "Any entity that is addressable in some way" {};}}', + after: `dm PPT "Base data structures to support People, Places and Things" +{ + + cdm Conceptual "Need to start at Conceptual Level" + { + + cassoc Training "Information delivered over time from one party to another " + { + + }; + + centity AddressableEntity "Any entity that is addressable in some way" + { + + }; + } }` From 16d7123f0355bc0fd9b6a0f82b74251c2f351e23 Mon Sep 17 00:00:00 2001 From: maytheu Date: Thu, 14 Sep 2023 20:41:15 +0100 Subject: [PATCH 04/12] . --- .../universal-data-definition-language-formatter.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts index f85631e..44e54ca 100644 --- a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts +++ b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts @@ -10,14 +10,14 @@ describe("Universal Data Definition Language Formatter", () => { it("should format cdm ", async () => { await universalDataDefinitionLanguageFormatting({ before: - 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis ee;}}', + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis uddlBasis "Formating conceptual basis entity";}}', after: `dm PPT "Base data structures to support People, Places and Things" { cdm Conceptual "Need to start at Conceptual Level" { - basis ee ; + basis uddlBasis "Formating conceptual basis entity"; } }` From 39b360596170e1065f9616a7c4dbf1db3941bc46 Mon Sep 17 00:00:00 2001 From: maytheu Date: Mon, 18 Sep 2023 14:00:13 +0100 Subject: [PATCH 05/12] test passes with no formmater --- ...rsal-data-definition-language-formatter.ts | 26 ++++++++++++------- ...data-definition-language-formatter.test.ts | 13 +++++++--- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/language-server/universal-data-definition-language-formatter.ts b/src/language-server/universal-data-definition-language-formatter.ts index 86896e1..345eda7 100644 --- a/src/language-server/universal-data-definition-language-formatter.ts +++ b/src/language-server/universal-data-definition-language-formatter.ts @@ -21,22 +21,29 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter close.surround(Formatting.noSpace()).prepend(Formatting.newLine({allowMore: true})).append(Formatting.newLine({allowMore: true})); } + protected formatNode(node: AstNode): void { + const formatter = this.getNodeFormatter(node); + formatter.property('name').prepend(Formatting.newLine()).surround(Formatting.oneSpace({allowMore: true})) + } + protected format(node: AstNode): void { // This method is called for every AstNode in a document if (ast.isDataModel(node)) { this.formatDataModel(node); } - if(ast.isConceptualAssociation(node)){ - this.formatConceptualAssociation(node) - } + // test passes with this commetned check + // if(ast.isConceptualAssociation(node)){ + // this.formatConceptualAssociation(node) + // } if(ast.isConceptualEntity(node)){ this.formatConceptualEntity(node) } - - if(ast.isConceptualBasisEntity(node)){ - this.formatConceptualBasisEntity(node) - } + + // test passes with this commetned check + // if(ast.isConceptualBasisEntity(node)){ + // this.formatConceptualBasisEntity(node) + // } } @@ -102,9 +109,8 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter } protected formatConceptualBasisEntity(basis: ast.ConceptualBasisEntity): void { - const formatter = this.getNodeFormatter(basis); - formatter.property('name').prepend(Formatting.newLine()).surround(Formatting.oneSpace({allowMore: true})); - } + this.formatNode(basis) + } protected formatConceptualAssociation(cassoc: ast.ConceptualAssociation): void { this.formatContainer(cassoc) diff --git a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts index 44e54ca..f2baef2 100644 --- a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts +++ b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts @@ -7,10 +7,10 @@ const universalDataDefinitionLanguageFormatting = expectFormatting(universalData ); describe("Universal Data Definition Language Formatter", () => { - it("should format cdm ", async () => { + it("should format cdm array with conceptual elemnt", async () => { await universalDataDefinitionLanguageFormatting({ before: - 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis uddlBasis "Formating conceptual basis entity";}}', + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis uddlBasis "Formating conceptual basis entity"; domain cdmDomain "Entry for conceptual domain"; cdm anothercdm "A cdm with another data" {observable Information "Something a party can learn";}}}', after: `dm PPT "Base data structures to support People, Places and Things" { @@ -18,13 +18,20 @@ describe("Universal Data Definition Language Formatter", () => { { basis uddlBasis "Formating conceptual basis entity"; + domain cdmDomain "Entry for conceptual domain"; + cdm anothercdm "A cdm with another data" + { + + observable Information "Something a party can learn"; + } + } }` }); }); - it("should format concptual element", async () => { + it("should format conceptual element", async () => { await universalDataDefinitionLanguageFormatting({ before: 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cassoc Training "Information delivered over time from one party to another " {};centity AddressableEntity "Any entity that is addressable in some way" {};}}', From cfe58aedf6ac29197ff43d00be6613ba42b78eda Mon Sep 17 00:00:00 2001 From: maytheu Date: Tue, 19 Sep 2023 16:57:58 +0100 Subject: [PATCH 06/12] improve test cases --- ...rsal-data-definition-language-formatter.ts | 24 ++--- ...data-definition-language-formatter.test.ts | 91 ++++++++++++++++--- 2 files changed, 85 insertions(+), 30 deletions(-) diff --git a/src/language-server/universal-data-definition-language-formatter.ts b/src/language-server/universal-data-definition-language-formatter.ts index 345eda7..f31726b 100644 --- a/src/language-server/universal-data-definition-language-formatter.ts +++ b/src/language-server/universal-data-definition-language-formatter.ts @@ -31,19 +31,12 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter if (ast.isDataModel(node)) { this.formatDataModel(node); } - // test passes with this commetned check - // if(ast.isConceptualAssociation(node)){ - // this.formatConceptualAssociation(node) - // } - - if(ast.isConceptualEntity(node)){ - this.formatConceptualEntity(node) + else if(ast.isConceptualAssociation(node)){ + this.formatConceptualAssociation(node) } - - // test passes with this commetned check - // if(ast.isConceptualBasisEntity(node)){ - // this.formatConceptualBasisEntity(node) - // } + else if(ast.isConceptualEntity(node)){ + this.formatConceptualEntity(node) + } } @@ -108,10 +101,6 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter }) } - protected formatConceptualBasisEntity(basis: ast.ConceptualBasisEntity): void { - this.formatNode(basis) - } - protected formatConceptualAssociation(cassoc: ast.ConceptualAssociation): void { this.formatContainer(cassoc) @@ -120,8 +109,6 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter }) } - protected formatConceptualCharacteristic(xter: ast.ConceptualCharacteristic): void {} - protected formatConceptualComposition(comp: ast.ConceptualComposition ): void { this.formatContainer(comp) } @@ -134,6 +121,7 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter } } + /**Formatting logicals */ protected formatLogicalElement(elem: ast.LogicalElement): void { const formatter = this.getNodeFormatter(elem); formatter.property('name').prepend(Formatting.newLine()).surround(Formatting.oneSpace({allowMore: true})); diff --git a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts index f2baef2..0327f70 100644 --- a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts +++ b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts @@ -2,23 +2,20 @@ import { createUniversalDataDefinitionLanguageServices } from "../../src/languag import { EmptyFileSystem } from "langium"; import { expectFormatting } from "langium/test"; -const universalDataDefinitionLanguageService =createUniversalDataDefinitionLanguageServices({...EmptyFileSystem,}).UniversalDataDefinitionLanguage; -const universalDataDefinitionLanguageFormatting = expectFormatting(universalDataDefinitionLanguageService -); +const universalDataDefinitionLanguageService = createUniversalDataDefinitionLanguageServices({...EmptyFileSystem,}).UniversalDataDefinitionLanguage; +const universalDataDefinitionLanguageFormatting = expectFormatting(universalDataDefinitionLanguageService); describe("Universal Data Definition Language Formatter", () => { - it("should format cdm array with conceptual elemnt", async () => { + it("should format cdm array", async () => { await universalDataDefinitionLanguageFormatting({ before: - 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis uddlBasis "Formating conceptual basis entity"; domain cdmDomain "Entry for conceptual domain"; cdm anothercdm "A cdm with another data" {observable Information "Something a party can learn";}}}', + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cdm anothercdm "A cdm with another data" {observable Information "Something a party can learn";}}}', after: `dm PPT "Base data structures to support People, Places and Things" { cdm Conceptual "Need to start at Conceptual Level" { - basis uddlBasis "Formating conceptual basis entity"; - domain cdmDomain "Entry for conceptual domain"; cdm anothercdm "A cdm with another data" { @@ -27,14 +24,14 @@ describe("Universal Data Definition Language Formatter", () => { } -}` +}`, }); }); - it("should format conceptual element", async () => { + it("should format cdm with conceptual association", async () => { await universalDataDefinitionLanguageFormatting({ before: - 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cassoc Training "Information delivered over time from one party to another " {};centity AddressableEntity "Any entity that is addressable in some way" {};}}', + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cassoc Training "Information delivered over time from one party to another " {};}}', after: `dm PPT "Base data structures to support People, Places and Things" { @@ -46,6 +43,22 @@ describe("Universal Data Definition Language Formatter", () => { }; + } + +}`, + }); + }); + + it("should format cdm with conceptual entity", async () => { + await universalDataDefinitionLanguageFormatting({ + before: + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{centity AddressableEntity "Any entity that is addressable in some way" {};}}', + after: `dm PPT "Base data structures to support People, Places and Things" +{ + + cdm Conceptual "Need to start at Conceptual Level" + { + centity AddressableEntity "Any entity that is addressable in some way" { @@ -53,7 +66,61 @@ describe("Universal Data Definition Language Formatter", () => { } -}` +}`, }); }); -}); \ No newline at end of file + + it('should format cdm with conceptual basis',async () => { + await universalDataDefinitionLanguageFormatting({ + before: + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis uddlBasis "Formating conceptual basis entity"; }}', + after: `dm PPT "Base data structures to support People, Places and Things" +{ + + cdm Conceptual "Need to start at Conceptual Level" + { + + basis uddlBasis "Formating conceptual basis entity"; + } + +}`, + }) + }) + + it('should format cdm with conceptual domain',async () => { + await universalDataDefinitionLanguageFormatting({ + before: + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{domain NaturalPerson "Base definition of a natural person"; }}', + after: `dm PPT "Base data structures to support People, Places and Things" +{ + + cdm Conceptual "Need to start at Conceptual Level" + { + + domain NaturalPerson "Base definition of a natural person"; + } + +}`, + }) + }) + + it("should format ldm array",async () => { + await universalDataDefinitionLanguageFormatting({ + before: 'dm Book "Base definition for book requirement" {ldm library "contains available books" {ldm BookShelf "Books related by category"{}}}', + after: `dm Book "Base definition for book requirement" +{ + + ldm library "contains available books" + { + + ldm BookShelf "Books related by category" + { + + } + + } + +}` + }) + }) +}); From 731cd27dc997872fcebdd1d9f9b43cb265def1c9 Mon Sep 17 00:00:00 2001 From: maytheu Date: Thu, 28 Sep 2023 16:55:06 +0100 Subject: [PATCH 07/12] remove extra lines from test --- ...sal-data-definition-language-formatter.test.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts index 0327f70..908d6e4 100644 --- a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts +++ b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts @@ -8,8 +8,7 @@ const universalDataDefinitionLanguageFormatting = expectFormatting(universalData describe("Universal Data Definition Language Formatter", () => { it("should format cdm array", async () => { await universalDataDefinitionLanguageFormatting({ - before: - 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cdm anothercdm "A cdm with another data" {observable Information "Something a party can learn";}}}', + before:'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cdm anothercdm "A cdm with another data" {observable Information "Something a party can learn";}}}', after: `dm PPT "Base data structures to support People, Places and Things" { @@ -30,8 +29,7 @@ describe("Universal Data Definition Language Formatter", () => { it("should format cdm with conceptual association", async () => { await universalDataDefinitionLanguageFormatting({ - before: - 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cassoc Training "Information delivered over time from one party to another " {};}}', + before:'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cassoc Training "Information delivered over time from one party to another " {};}}', after: `dm PPT "Base data structures to support People, Places and Things" { @@ -51,8 +49,7 @@ describe("Universal Data Definition Language Formatter", () => { it("should format cdm with conceptual entity", async () => { await universalDataDefinitionLanguageFormatting({ - before: - 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{centity AddressableEntity "Any entity that is addressable in some way" {};}}', + before:'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{centity AddressableEntity "Any entity that is addressable in some way" {};}}', after: `dm PPT "Base data structures to support People, Places and Things" { @@ -72,8 +69,7 @@ describe("Universal Data Definition Language Formatter", () => { it('should format cdm with conceptual basis',async () => { await universalDataDefinitionLanguageFormatting({ - before: - 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis uddlBasis "Formating conceptual basis entity"; }}', + before: 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis uddlBasis "Formating conceptual basis entity"; }}', after: `dm PPT "Base data structures to support People, Places and Things" { @@ -89,8 +85,7 @@ describe("Universal Data Definition Language Formatter", () => { it('should format cdm with conceptual domain',async () => { await universalDataDefinitionLanguageFormatting({ - before: - 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{domain NaturalPerson "Base definition of a natural person"; }}', + before: 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{domain NaturalPerson "Base definition of a natural person"; }}', after: `dm PPT "Base data structures to support People, Places and Things" { From 5c61e26586e61ee010b1e8551bb0107a804e5631 Mon Sep 17 00:00:00 2001 From: maytheu Date: Thu, 28 Sep 2023 20:48:26 +0100 Subject: [PATCH 08/12] logical model formatter --- ...rsal-data-definition-language-formatter.ts | 104 +++++++++++++++++- 1 file changed, 100 insertions(+), 4 deletions(-) diff --git a/src/language-server/universal-data-definition-language-formatter.ts b/src/language-server/universal-data-definition-language-formatter.ts index f31726b..846f358 100644 --- a/src/language-server/universal-data-definition-language-formatter.ts +++ b/src/language-server/universal-data-definition-language-formatter.ts @@ -36,7 +36,32 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter } else if(ast.isConceptualEntity(node)){ this.formatConceptualEntity(node) - } + } + else if(ast.isLogicalEnumerated(node)){ + this.formatLogicalEnumerated(node) + } + else if(ast.isLogicalMeasurement(node)){ + this.formatLogicalMeasurement(node) + } + else if(ast.isLogicalMeasurementSystemAxis(node)){ + this.formatLogicalMeasurementSystemAxis(node) + } + else if(ast.isLogicalValueTypeUnit(node)){ + this.formatLogicalValueTypeUnit(node) + } + else if(ast.isLogicalMeasurement(node)){ + this.formatLogicalMeasurement(node) + } + else if(ast.isLogicalEntity(node)){ + this.formatLogicalEntity(node) + } + else if(ast.isLogicalAssociation(node)){ + this.formatLogicalAssociation(node) + } + else if(ast.isLogicalParticipantPathNode(node)){ + this.formatLogicalParticipantPathNode(node) + } + } @@ -103,7 +128,6 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter protected formatConceptualAssociation(cassoc: ast.ConceptualAssociation): void { this.formatContainer(cassoc) - cassoc.composition.forEach(comp => { this.formatConceptualComposition(comp) }) @@ -114,8 +138,7 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter } protected formatConceptualParticipant(participant: ast.ConceptualParticipant): void { - this.formatContainer(participant) - + this.formatContainer(participant) if(participant?.type){ this.formatConceptualEntity(participant.type.ref!) } @@ -128,6 +151,79 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter this.formatObj(elem); } + protected formatLogicalEnumerated(lenum: ast.LogicalEnumerated): void { + this.formatContainer(lenum) + lenum.label.forEach(label => { + this.formatContainer(label) + }) + } + + protected formatLogicalMeasurementSystem(sys: ast.LogicalMeasurementSystem): void { + this.formatContainer(sys); + sys.constraint.forEach(sysConst => { + this.formatContainer(sysConst) + }) + sys.referencePoint.forEach(ref => { + this.formatLogicalReferencePoint(ref); + }) + } + + protected formatLogicalMeasurementSystemAxis(sysAxis: ast.LogicalMeasurementSystemAxis): void { + this.formatContainer(sysAxis); + sysAxis.constraint.forEach(sysConst => { + this.formatContainer(sysConst); + }) + } + + protected formatLogicalReferencePoint(refPoint: ast.LogicalReferencePoint): void { + this.formatContainer(refPoint); + refPoint.referencePointPart.forEach(pointPart => { + this.formatContainer(pointPart); + }) + } + + protected formatLogicalValueTypeUnit(typeUnit: ast.LogicalValueTypeUnit):void { + this.formatContainer(typeUnit); + if(typeUnit.constraint){ + this.formatContainer(typeUnit); + } + } + + protected formatLogicalMeasurement(measure: ast.LogicalMeasurement): void { + this.formatContainer(measure); + measure.attribute.forEach(attr => { + this.formatContainer(attr) + }) + measure.constraint.forEach(mesConst => { + this.formatContainer(mesConst) + }) + } + + protected formatLogicalEntity(entity: ast.LogicalEntity): void { + this.formatContainer(entity); + entity.composition.forEach(comp => { + this.formatContainer(comp); + }) + } + + protected formatLogicalAssociation(asso: ast.LogicalAssociation): void { + this.formatContainer(asso); + asso.composition.forEach(comp => { + this.formatContainer(comp); + }) + asso.participant.forEach(part => { + this.formatLogicalParticipant(part); + }) + } + + protected formatLogicalParticipant(part: ast.LogicalParticipant): void { + this.formatContainer(part) + } + + protected formatLogicalParticipantPathNode(pathBode: ast.LogicalParticipantPathNode): void { + this.formatContainer(pathBode) + } + protected formatPlatformElement(elem: ast.PlatformElement): void { const formatter = this.getNodeFormatter(elem); formatter.property('name').prepend(Formatting.newLine()).surround(Formatting.oneSpace({allowMore: true})); From 7693f723adf67bd8bcf42c25893703206e3afdab Mon Sep 17 00:00:00 2001 From: maytheu Date: Fri, 29 Sep 2023 19:53:59 +0100 Subject: [PATCH 09/12] platform data model formatter --- ...rsal-data-definition-language-formatter.ts | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/language-server/universal-data-definition-language-formatter.ts b/src/language-server/universal-data-definition-language-formatter.ts index 846f358..5b2a13c 100644 --- a/src/language-server/universal-data-definition-language-formatter.ts +++ b/src/language-server/universal-data-definition-language-formatter.ts @@ -61,7 +61,18 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter else if(ast.isLogicalParticipantPathNode(node)){ this.formatLogicalParticipantPathNode(node) } - + else if(ast.isPlatformEntity(node)){ + this.formatPlatformEntity(node) + } + else if(ast.isPlatformStruct(node)){ + this.formatPlatformStruct(node) + } + else if(ast.isPlatformAssociation(node)){ + this.formatPlatformAssociation(node); + } + else if(ast.isPlatformCompositeQuery(node)){ + this.formatPlatformCompositeQuery(node); + } } @@ -224,11 +235,50 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter this.formatContainer(pathBode) } + protected formatLogicalCompositeQuery(query: ast.LogicalCompositeQuery): void { + this.formatContainer(query) + query.composition.forEach(comp => { + this.formatContainer(query) + }) + } + protected formatPlatformElement(elem: ast.PlatformElement): void { const formatter = this.getNodeFormatter(elem); formatter.property('name').prepend(Formatting.newLine()).surround(Formatting.oneSpace({allowMore: true})); this.formatObj(elem); } + + protected formatPlatformEntity(entity: ast.PlatformEntity): void { + this.formatContainer(entity) + entity.composition.forEach(comp => { + this.formatContainer(comp) + }) + } + + protected formatPlatformStruct(str: ast.PlatformStruct): void { + this.formatContainer(str) + str.member.forEach(mem => { + this.formatContainer(mem) + }) + } + + protected formatPlatformAssociation(asso: ast.PlatformAssociation): void { + this.formatContainer(asso) + asso.participant.forEach(part => { + this.formatPlatformParticipant(part); + }) + } + + protected formatPlatformParticipant(part: ast.PlatformParticipant): void { + this.formatContainer(part) + } + + protected formatPlatformCompositeQuery(query: ast.PlatformCompositeQuery): void { + this.formatContainer(query) + query.composition.forEach(comp => { + this.formatContainer(comp); + }) + } } From f2333d4ea0f82c388c0194c16f4405fcd5a7f67f Mon Sep 17 00:00:00 2001 From: maytheu Date: Mon, 2 Oct 2023 14:13:24 +0100 Subject: [PATCH 10/12] format association before entities --- ...universal-data-definition-language-formatter.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/language-server/universal-data-definition-language-formatter.ts b/src/language-server/universal-data-definition-language-formatter.ts index 5b2a13c..2a44fd2 100644 --- a/src/language-server/universal-data-definition-language-formatter.ts +++ b/src/language-server/universal-data-definition-language-formatter.ts @@ -52,24 +52,24 @@ export class UniversalDataDefinitionLanguageFormatter extends AbstractFormatter else if(ast.isLogicalMeasurement(node)){ this.formatLogicalMeasurement(node) } - else if(ast.isLogicalEntity(node)){ - this.formatLogicalEntity(node) - } - else if(ast.isLogicalAssociation(node)){ + else if(ast.isLogicalAssociation(node)){ this.formatLogicalAssociation(node) } + else if(ast.isLogicalEntity(node)){ + this.formatLogicalEntity(node) + } else if(ast.isLogicalParticipantPathNode(node)){ this.formatLogicalParticipantPathNode(node) } + else if(ast.isPlatformAssociation(node)){ + this.formatPlatformAssociation(node); + } else if(ast.isPlatformEntity(node)){ this.formatPlatformEntity(node) } else if(ast.isPlatformStruct(node)){ this.formatPlatformStruct(node) } - else if(ast.isPlatformAssociation(node)){ - this.formatPlatformAssociation(node); - } else if(ast.isPlatformCompositeQuery(node)){ this.formatPlatformCompositeQuery(node); } From 5a563531d1a8dac8eebc7854c386798e6e45fab0 Mon Sep 17 00:00:00 2001 From: maytheu Date: Wed, 4 Oct 2023 22:08:31 +0100 Subject: [PATCH 11/12] ldm test --- ...data-definition-language-formatter.test.ts | 107 +++++++++++++++--- 1 file changed, 91 insertions(+), 16 deletions(-) diff --git a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts index 908d6e4..e1d6186 100644 --- a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts +++ b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts @@ -2,13 +2,19 @@ import { createUniversalDataDefinitionLanguageServices } from "../../src/languag import { EmptyFileSystem } from "langium"; import { expectFormatting } from "langium/test"; -const universalDataDefinitionLanguageService = createUniversalDataDefinitionLanguageServices({...EmptyFileSystem,}).UniversalDataDefinitionLanguage; -const universalDataDefinitionLanguageFormatting = expectFormatting(universalDataDefinitionLanguageService); +const universalDataDefinitionLanguageService = + createUniversalDataDefinitionLanguageServices({ + ...EmptyFileSystem, + }).UniversalDataDefinitionLanguage; +const universalDataDefinitionLanguageFormatting = expectFormatting( + universalDataDefinitionLanguageService +); describe("Universal Data Definition Language Formatter", () => { it("should format cdm array", async () => { await universalDataDefinitionLanguageFormatting({ - before:'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cdm anothercdm "A cdm with another data" {observable Information "Something a party can learn";}}}', + before: + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cdm anothercdm "A cdm with another data" {observable Information "Something a party can learn";}}}', after: `dm PPT "Base data structures to support People, Places and Things" { @@ -29,7 +35,8 @@ describe("Universal Data Definition Language Formatter", () => { it("should format cdm with conceptual association", async () => { await universalDataDefinitionLanguageFormatting({ - before:'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cassoc Training "Information delivered over time from one party to another " {};}}', + before: + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{cassoc Training "Information delivered over time from one party to another " {};}}', after: `dm PPT "Base data structures to support People, Places and Things" { @@ -49,7 +56,8 @@ describe("Universal Data Definition Language Formatter", () => { it("should format cdm with conceptual entity", async () => { await universalDataDefinitionLanguageFormatting({ - before:'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{centity AddressableEntity "Any entity that is addressable in some way" {};}}', + before: + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{centity AddressableEntity "Any entity that is addressable in some way" {};}}', after: `dm PPT "Base data structures to support People, Places and Things" { @@ -67,9 +75,10 @@ describe("Universal Data Definition Language Formatter", () => { }); }); - it('should format cdm with conceptual basis',async () => { + it("should format cdm with conceptual basis", async () => { await universalDataDefinitionLanguageFormatting({ - before: 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis uddlBasis "Formating conceptual basis entity"; }}', + before: + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{basis uddlBasis "Formating conceptual basis entity"; }}', after: `dm PPT "Base data structures to support People, Places and Things" { @@ -80,12 +89,13 @@ describe("Universal Data Definition Language Formatter", () => { } }`, - }) - }) + }); + }); - it('should format cdm with conceptual domain',async () => { + it("should format cdm with conceptual domain", async () => { await universalDataDefinitionLanguageFormatting({ - before: 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{domain NaturalPerson "Base definition of a natural person"; }}', + before: + 'dm PPT "Base data structures to support People, Places and Things"{cdm Conceptual "Need to start at Conceptual Level"{domain NaturalPerson "Base definition of a natural person"; }}', after: `dm PPT "Base data structures to support People, Places and Things" { @@ -96,12 +106,13 @@ describe("Universal Data Definition Language Formatter", () => { } }`, - }) - }) + }); + }); - it("should format ldm array",async () => { + it("should format ldm array", async () => { await universalDataDefinitionLanguageFormatting({ - before: 'dm Book "Base definition for book requirement" {ldm library "contains available books" {ldm BookShelf "Books related by category"{}}}', + before: + 'dm Book "Base definition for book requirement" {ldm library "contains available books" {ldm BookShelf "Books related by category"{}}}', after: `dm Book "Base definition for book requirement" { @@ -115,7 +126,71 @@ describe("Universal Data Definition Language Formatter", () => { } +}`, + }); + }); + + it("should format logical element", async () => { + await universalDataDefinitionLanguageFormatting({ + before: + 'dm logicalElement "Some logial element" {ldm logicalData "logical description"{lunit LengthUnit "Defines units of length";bool IsEnabled "Represents whether an item is enabled";nat NumberOfChildren "Represents the number of children a person has";}}', + after: `dm logicalElement "Some logial element" +{ + + ldm logicalData "logical description" + { + + lunit LengthUnit "Defines units of length"; + bool IsEnabled "Represents whether an item is enabled"; + nat NumberOfChildren "Represents the number of children a person has"; + } + +}`, + }); + }); + + it("should format logical relationships",async () => { + await universalDataDefinitionLanguageFormatting({ + before:'dm logicalElement "Some logial element" {ldm logicalData "logical description"{csa logicalCoordinate "Logical system axis";coord GeographicCoordinates "Represents geographic coordinates" {axis:"WGS84" angleEq:"lat = atan((exp(n) - exp(-n)) / (exp(n) + exp(-n)))" distanceEq:"distance = R * arctan(sqrt(1 - e^2) * tan(lat))"[logicalCoordinate]};}}', + after:`dm logicalElement "Some logial element" +{ + + ldm logicalData "logical description" + { + + csa logicalCoordinate "Logical system axis"; + coord GeographicCoordinates "Represents geographic coordinates" { + + axis: + "WGS84" + angleEq: + "lat = atan((exp(n) - exp(-n)) / (exp(n) + exp(-n)))" + distanceEq: + "distance = R * arctan(sqrt(1 - e^2) * tan(lat))" + [ + logicalCoordinate + ] + }; + + } + }` - }) + }) }) + + it("should format platform data model", async () => { + await universalDataDefinitionLanguageFormatting({ + before: + 'dm Library "Defint library collection" {pdm Collection "A collection of related books"{}}', + after: `dm Library "Defint library collection" +{ + + pdm Collection "A collection of related books" + { + + } + +}`, + }); + }); }); From f1964568d8e00812b9c9c7bf4f1b16a466630a95 Mon Sep 17 00:00:00 2001 From: maytheu Date: Mon, 9 Oct 2023 20:19:24 +0100 Subject: [PATCH 12/12] formatting platform element --- ...data-definition-language-formatter.test.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts index e1d6186..15debac 100644 --- a/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts +++ b/uddl_test/uddl_test_formatting/universal-data-definition-language-formatter.test.ts @@ -193,4 +193,26 @@ describe("Universal Data Definition Language Formatter", () => { }`, }); }); + + it('should format platform element', async () => { + await universalDataDefinitionLanguageFormatting({ + before:'dm MyDataModel {ldm MyLogicalDataModel {bool LogicalBoolean "Represents a logical boolean";}pdm MyPlatformDataModel {bool BooleanValue "Represents a boolean value" -> MyLogicalDataModel.LogicalBoolean;}}', + after:`dm MyDataModel +{ + + ldm MyLogicalDataModel + { + + bool LogicalBoolean "Represents a logical boolean"; + } + + pdm MyPlatformDataModel + { + + bool BooleanValue "Represents a boolean value" -> MyLogicalDataModel.LogicalBoolean; + } + +}` + }) + }) });