Skip to content

Commit

Permalink
exporting is bijectional modulo incoherent sources and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Oct 3, 2012
1 parent 4b36085 commit 652ba8a
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions topics/mega/src/backend/MegaExport.rsc
Expand Up @@ -5,16 +5,18 @@ import structure::MegaADT;
import structure::MegaGrammar;
import String;

list[MegaRelation] processed = [];

str exportmega(megamodel(str name, str desc, list[str] incs, list[MegaDeclaration] decls, list[MegaRelation] rels))
="{- <desc> -}
'
'megamodel <name> .
'
'<for(str i <- incs){>include <i> .
'<}>
'<for(MegaDeclaration d <- decls){><exportdecl(d)> .
'<for(MegaDeclaration d <- decls){><exportdeclR(d,rels)> .
'<}>
'<for(MegaRelation r <- rels){><exportrel(r)> .
'<for(MegaRelation r <- rels, r notin processed){><exportrelR(r,rels)> .
'<}>";

str exportdecl(artifact(MegaMod m, str id, bool plus)) = "<exportmod(m)>Artifact<if(plus){>+<}> <id>";
Expand All @@ -32,7 +34,7 @@ str exportmod(local()) = "local ";
str exportmod(variable()) = "variable ";
str exportmod(MegaMod m) = "";

str exportrel(subsetOf(str x, str y)) = "<x> subsefOf <y>";
str exportrel(subsetOf(str x, str y)) = "<x> subsetOf <y>";
str exportrel(elementOf(str x, str y)) = "<x> elementOf <y>";
str exportrel(partOf(str x, str y)) = "<x> partOf <y>";
str exportrel(correspondsTo(str x, str y)) = "<x> correspondsTo <y>";
Expand All @@ -47,3 +49,48 @@ str exportrel(hasOutput(str x, str y)) = "<x> hasOutput <y>";
str exportrel(domainOf(str x, str y)) = "<x> domainOf <y>";
str exportrel(hasRange(str x, str y)) = "<x> hasRange <y>";
default str exportrel(MegaRelation r) = "UNKNOWN REL";

str exportdeclR(MegaDeclaration d, list[MegaRelation] rels)
{
str s = "";
for (r <- rels, r.x == d.id)
if (domainOf(a,b) := r, /hasRange(b,str c) := rels)
{
s = " : <a> -\> <c>";
processed += r;
processed += hasRange(b,c);
break;
}
elseif (hasRange(a,b) := r, /domainOf(c,a) := rels)
{
s = " : <c> -\> <b>";
processed += r;
processed += domainOf(c,a);
break;
}
else
{
s = replaceFirst(exportrel(r),"<r.x> "," ");
processed += r;
break;
}
return exportdecl(d)+s;
}

str exportrelR(MegaRelation r, list[MegaRelation] rels)
{
if (inputOf(str a, str b) := r, /hasOutput(b,str c) := rels)
{
processed += r;
processed += hasOutput(b,c);
return "<b>(<a>) |-\> <c>";
}
elseif (hasOutput(a,b) := r, /inputOf(c,a) := rels)
{
processed += r;
processed += inputOf(c,a);
return "<a>(<c>) |-\> <b>";
}
else
return exportrel(r);
}

0 comments on commit 652ba8a

Please sign in to comment.