X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=parser.js;h=8a4c52499f17df2fe92e28150b72e825b98c0f69;hb=d6c9499e06c65780d5f4c95664c2cb851ff6f2de;hp=8a0932160a0a50f7f1b551242aed17dac2f9c30d;hpb=525c4d2aa73ae124da17a3c64a2ca44d13fcc49d;p=erdiag.git diff --git a/parser.js b/parser.js index 8a09321..8a4c524 100644 --- a/parser.js +++ b/parser.js @@ -7,6 +7,7 @@ class ErDiags this.inheritances = []; this.associations = []; this.txt2json(description); + this.tables = []; // Cache SVG graphs returned by server (in addition to server cache = good perfs) this.mcdGraph = ""; this.mldGraph = ""; @@ -15,7 +16,7 @@ class ErDiags static get TYPES() { - // SQLite types without null (TODO: be more general) + // SQLite storage classes without null return ["integer","real","text","blob"]; } @@ -66,7 +67,7 @@ class ErDiags { case '[': // Entity = { name: { attributes, [weak] } } - let name = lines[start].match(/\w+/)[0]; + let name = lines[start].match(/[^\[\]\s]+/)[0]; let entity = { attributes: this.parseAttributes(lines, start+1, end) }; if (lines[start].charAt(1) == '[') entity.weak = true; @@ -78,7 +79,7 @@ class ErDiags case '{': //association // Association = { [name], [attributes], [weak], entities: ArrayOf entity indices } let relationship = { }; - let nameRes = lines[start].match(/\w+/); + let nameRes = lines[start].match(/[^{}\s]+/); if (nameRes !== null) relationship.name = nameRes[0]; if (lines[start].charAt(1) == '{') @@ -94,15 +95,20 @@ class ErDiags let attributes = []; for (let i=start; i { this.mcdGraph = graphSvg; element.innerHTML = graphSvg; - }) + }); } // "Modèle logique des données" @@ -268,10 +274,30 @@ class ErDiags element.innerHTML = this.mcdGraph; return; } - //UNIMPLEMENTED - // TODO: analyze cardinalities (eat attributes, create new tables...) - // mldDot = ... + // Build dot graph input + let mldDot = 'graph {\n'; + // Nodes: + Object.keys(this.entities).forEach( name => { + //mld. ... --> devient table + // mldDot = ... + }); + // Relationships: + this.associations.forEach( a => { + a.entities.forEach( e => { // e.card e.name ... + // Pass 1 : entites deviennent tables + // Pass 2 : sur les assoces + // multi-arite : sub-loop si 0,1 ou 1,1 : aspiré comme attribut de l'association (phase 1) + // ensuite, que du 0,n ou 1,n : si == 1, OK une table + // si 2 ou + : n tables + 1 pour l'assoce, avec attrs clés étrangères + // clé étrangère NOT NULL si 1,1 + }); + }); // this.graphMld = ... + //console.log(mldDot); + ErDiags.AjaxGet(mldDot, graphSvg => { + this.mldGraph = graphSvg; + element.innerHTML = graphSvg; + }); } fillSql(id)