Skip to content

Commit

Permalink
Parser now uses default if parser p[rojection is missing, test change…
Browse files Browse the repository at this point in the history
…d to test whether parser and unparser (reader and writer) are both correct.
  • Loading branch information
joswarmer committed Nov 28, 2024
1 parent 622de79 commit c5b9e8b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 22 deletions.
46 changes: 41 additions & 5 deletions packages/meta/src/parsergen/parserTemplates/ParserGenUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,49 @@ export class ParserGenUtil {
* @param editUnit the edit definition to serach for the projection groups
*/
static findParsableProjectionGroup(editUnit: FreEditUnit) {
let projectionGroup: FreEditProjectionGroup | undefined = editUnit.projectiongroups.find(
(g) => g.name === EditorDefaults.parserGroupName,
const parserProjectionGroup: FreEditProjectionGroup | undefined = editUnit.projectiongroups.find(
(g) => g.name === EditorDefaults.parserGroupName
);
if (!projectionGroup) {
projectionGroup = editUnit.getDefaultProjectiongroup();
const defaultProjectionGroup = editUnit.getDefaultProjectiongroup();
return ParserGenUtil.joinProjectionGroups(parserProjectionGroup, defaultProjectionGroup);
}

/**
* Join the parser projection with the default projection for generating a (un)parser
* @param parserProjection
* @param defaultProjection
* @private
*/
private static joinProjectionGroups(parserProjection: FreEditProjectionGroup | undefined, defaultProjection: FreEditProjectionGroup | undefined): FreEditProjectionGroup | undefined {
if (parserProjection === undefined) {
return defaultProjection;
}
return projectionGroup;
if (defaultProjection === undefined) {
return undefined;
}
const projection = new FreEditProjectionGroup();
projection.name = defaultProjection.name
projection.globalProjections = defaultProjection.globalProjections;
projection.extras = defaultProjection.extras;
projection.owningDefinition = (!!parserProjection.owningDefinition ? parserProjection.owningDefinition : defaultProjection.owningDefinition);
projection.aglParseLocation = (!!parserProjection.aglParseLocation ? parserProjection.aglParseLocation : defaultProjection.aglParseLocation);
projection.location = (!!parserProjection.location ? parserProjection.location : defaultProjection.location);

parserProjection.projections.forEach(p => {
console.log("Pushing from parser: " + p.classifier?.name)
projection.projections.push(p)
} )
defaultProjection.projections.forEach(defaultProj => {
const found = parserProjection.projections.find(existingProj =>
existingProj.classifier?.referred === defaultProj.classifier?.referred);
if (found === undefined) {
console.log("Pushing from default: " + defaultProj.classifier?.name)
projection.projections.push(defaultProj);
} else {
console.log("Found from parser: " + defaultProj.classifier?.name)
}
});
return projection;
}

static findNonTableProjection(
Expand Down
6 changes: 4 additions & 2 deletions packages/meta/src/parsergen/parserTemplates/WriterTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,9 @@ export class WriterTemplate {
* Unparsing of '${name}' according to projection '${projection.name}'.
*/`;
// take care of named projections, the unparse method gets a different name
// except when it is the parser projection, this replaces the default projection with the same name.
let methodName: string = `unparse${name}`;
if (projection.name !== this.currentProjectionGroup?.name) {
if (projection.name !== this.currentProjectionGroup?.name && projection.name !== "parser") {
methodName += "_" + projection.name;
}
if (!!lines) {
Expand Down Expand Up @@ -611,7 +612,8 @@ export class WriterTemplate {
if (!!foundProjection) {
ListUtil.addIfNotPresent<FreEditClassifierProjection>(this.namedProjections, foundProjection);
}
result += `this.unparse${Names.classifier(item.superRef.referred)}_${item.projectionName}(modelelement, short);`;
result += `// SUPER
this.unparse${Names.classifier(item.superRef.referred)}_${item.projectionName}(modelelement, short);`;
} else {
// use the normal unparse method
result += `this.unparse${Names.classifier(item.superRef.referred)}(modelelement, short);`;
Expand Down
16 changes: 16 additions & 0 deletions packages/test/src/vehicles/defs/Vehicles-default.edit
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,19 @@ editor default
global {
boolean [GOOD | WRONG] // are the strings used to display a boolean value
}

Steamboat {
[
${typeName} Manufacturer: ${manufacturer:additional}
[=> IsMotorised]
NrOfPassengers: ${nrOfPassengers}
PreferedWaterWay: ${preferedWaterWay}
Is a heritage ship: ${isHeritage}
]}

PetrolCar {
[
${typeName} [=> Vehicle:additional]
[=> IsMotorised]
max content of boot (in m2): ${bootContent}
]}
16 changes: 1 addition & 15 deletions packages/test/src/vehicles/defs/Vehicles-parser.edit
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,7 @@ Bike {
Size of tyres: ${tyreSize}
]}

Steamboat {
[
${typeName} Manufacturer: ${manufacturer:additional}
[=> IsMotorised]
NrOfPassengers: ${nrOfPassengers}
PreferedWaterWay: ${preferedWaterWay}
Is a heritage ship: ${isHeritage}
]}

PetrolCar {
[
${typeName} [=> Vehicle:additional]
[=> IsMotorised]
max content of boot (in m2): ${bootContent}
]}
//Steamboat and PetrolCar defined in default

SolarCar {
[
Expand Down

0 comments on commit c5b9e8b

Please sign in to comment.