Skip to content

Commit

Permalink
generating ugly-laid out, but nicely conforming and automated visual …
Browse files Browse the repository at this point in the history
…instances
  • Loading branch information
grammarware committed Oct 6, 2012
1 parent eff7fdc commit 0e3a1f7
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 3 deletions.
2 changes: 2 additions & 0 deletions topics/mega/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//examples/guided.megal=UTF-8
3 changes: 3 additions & 0 deletions topics/mega/examples/.gitignore
@@ -0,0 +1,3 @@
*.megal.back
*.dot
*.pdf
7 changes: 7 additions & 0 deletions topics/mega/examples/Makefile
@@ -0,0 +1,7 @@
all: guided.pdf

%.pdf: %.dot
dot -Tpdf $*.dot > $*.pdf

clean:
rm -f *.back *.pdf *.dot
50 changes: 50 additions & 0 deletions topics/mega/examples/guided.megal
@@ -0,0 +1,50 @@
{- The baseline megamodel of the MPM 2012 paper -}

megamodel guided .

variable FunctionApp Xformation1a .
variable Function Xformation1 .
variable Artifact XformScript1 .
variable Artifact Grammar1 .
variable Language Language1 .
variable Artifact Program1 .
variable FunctionApp Xformation2a .
variable Function Xformation2 .
variable Artifact XformScript2 .
FunctionApp GGC1 .
FunctionApp GGC2 .
variable Artifact Grammar2 .
variable Language Language2 .
variable Artifact Program2 .
Language XeeBGF .
Artifact Master .
Language Intended .
Function GGC .

Xformation1a elementOf Xformation1 .
Xformation1a(Grammar1) |-> Master .
XformScript1 elementOf XeeBGF .
XformScript1 realizationOf Xformation1 .
GGC1 elementOf GGC .
GGC1(Grammar1) |-> XformScript1 .
Grammar1 definitionOf Language1 .
Program1 elementOf Language1 .
Master inputOf GGC1 .
Grammar1 correspondsTo Master .
Language1 correspondsTo Intended .
Program1 correspondsTo Program2 .

Xformation2a elementOf Xformation2 .
Xformation2a(Grammar2) |-> Master .
XformScript2 elementOf XeeBGF .
XformScript2 realizationOf Xformation2 .
GGC2 elementOf GGC .
GGC2(Grammar2) |-> XformScript2 .
Grammar2 definitionOf Language2 .
Program2 elementOf Language2 .
Master inputOf GGC2 .
Grammar2 correspondsTo Master .
Language2 correspondsTo Intended .
Program2 correspondsTo Program1 .

Master definitionOf Intended .
18 changes: 16 additions & 2 deletions topics/mega/src/backend/MegaDot.rsc
Expand Up @@ -5,6 +5,15 @@ import structure::MegaADT;
import structure::MegaGrammar;
import String;

import io::MegaL;
import IO;

public void main()
{
ast = readAST(|project://megal/examples/guided.megal|);
writeFile(|project://megal/examples/guided.dot|,exportmega(ast));
}

str exportmega(megamodel(str name, str desc, list[str] incs, list[MegaDeclaration] decls, list[MegaRelation] rels))
="digraph G {
'<for(MegaDeclaration d <- decls){><exportdecl(d)>
Expand All @@ -22,13 +31,18 @@ str exportdecl(objectGraph(MegaMod m, str id, bool plus, str comment)) = "<expor
str exportdecl(program(MegaMod m, str id, bool plus, str comment)) = "<exportmod(m,id,"blue")>";
str exportdecl(library(MegaMod m, str id, bool plus, str comment)) = "<exportmod(m,id,"blue")>";
str exportdecl(function(MegaMod m, str id, bool plus, str comment)) = "<exportmod(m,id,"green")>";
default str exportdecl(MegaDeclaration d) = "UNKNOWN DECL";
str exportdecl(functionapp(MegaMod m, str id, bool plus, str comment)) = "<exportmod(m,id,"darkgreen")>";
default str exportdecl(MegaDeclaration d) = "UNKNOWN DECL <d>";

str exportmod(local(),str id, str col) = makenode(id,col,"dashed");
str exportmod(variable(),str id, str col) = makenode(id,col,"dotted");
str exportmod(nomod(),str id,str col) = makenode(id,col,"solid");

str makenode(str id, str col, str style) = "\"<id>\" [label=\"<id>\",shape=box,style=\"filled,<style>\",fillcolor=\"<col>\"];";
str makenode(str id, str col, str style) = "\"<id>\" [label=\"<id>\",shape=box,style=\"filled,<style>\",fillcolor=\"<col>\"<fliptextcolor(col)>];";

str fliptextcolor("blue") = ",fontcolor=\"white\"";
str fliptextcolor("darkgreen") = ",fontcolor=\"white\"";
default str fliptextcolor(str c) = "";

str exportrel(subsetOf(str x, str y, str comment)) = makeedge(x,"subsetOf",y);
str exportrel(elementOf(str x, str y, str comment)) = makeedge(x,"elementOf",y);
Expand Down
5 changes: 5 additions & 0 deletions topics/mega/src/backend/MegaImplode.rsc
Expand Up @@ -63,6 +63,10 @@ MegaRelation map1rel("=\>", str x, str y, str comment) = definitionOf(x,y,commen
MegaRelation map1rel("realizationOf", str x, str y, str comment) = realizationOf(x,y,comment);
MegaRelation map1rel("descriptionOf", str x, str y, str comment) = descriptionOf(x,y,comment);
MegaRelation map1rel("definitionOf", str x, str y, str comment) = definitionOf(x,y,comment);
MegaRelation map1rel("inputOf", str x, str y, str comment) = inputOf(x,y,comment);
MegaRelation map1rel("hasOutput", str x, str y, str comment) = hasOutput(x,y,comment);
MegaRelation map1rel("domainOf", str x, str y, str comment) = domainOf(x,y,comment);
MegaRelation map1rel("hasRange", str x, str y, str comment) = hasRange(x,y,comment);
default MegaRelation map1rel(str b, str x, str y, str comment) = subsetOf(x,y,comment); // no error report

MegaDeclaration map1decl((MegaEntity)`<MegaArtifact a><MaybePlus plus><ID x><MegaBin _><ID _>`,MegaMod m, str id, str comment)
Expand All @@ -77,6 +81,7 @@ MegaDeclaration map1decl((MegaEntity)`<MegaArtifact a><MaybePlus plus><ID _>`,Me
case "Language": return language(m,id,isplus(plus),comment);
case "Technology": return technology(m,id,isplus(plus),comment);
case "Fragment": return fragment(m,id,isplus(plus),comment);
case "FunctionApp": return functionapp(m,id,isplus(plus),comment);
case "ObjectGraph": return objectGraph(m,id,isplus(plus),comment);
case "Program": return program(m,id,isplus(plus),comment);
case "Library": return library(m,id,isplus(plus),comment);
Expand Down
1 change: 1 addition & 0 deletions topics/mega/src/structure/MegaADT.rsc
Expand Up @@ -12,6 +12,7 @@ data MegaDeclaration
| program(MegaMod m, str id, bool plus, str comment)
| library(MegaMod m, str id, bool plus, str comment)
| function(MegaMod m, str id, bool plus, str comment)
| functionapp(MegaMod m, str id, bool plus, str comment)
;
data MegaMod = local() | variable() | nomod();
data MegaRelation
Expand Down
3 changes: 2 additions & 1 deletion topics/mega/src/structure/MegaGrammar.rsc
Expand Up @@ -21,7 +21,7 @@ syntax MegaEntity
= MegaArtifact MaybePlus ID id (MegaBin ID)?
| "Function" MaybePlus ID id MegaFun?
;
syntax MegaArtifact = "Artifact" | "File" | "Language" | "Technology" | "Fragment" | "ObjectGraph" | "Program" | "Library";
syntax MegaArtifact = "Artifact" | "File" | "Language" | "Technology" | "Fragment" | "ObjectGraph" | "Program" | "Library" | "FunctionApp";
syntax MegaRel
= ID MegaBin ID
| ID MegaFun
Expand All @@ -35,6 +35,7 @@ syntax MegaBin
| ( "~\>" | "dependsOn" | "refersTo" )
| ( "-|" | "conformsTo" )
| ( "=\>" | "realizationOf" | "descriptionOf" | "definitionOf" )
| ( "inputOf" | "hasOutput" | "domainOf" | "hasRange" )
;
syntax MegaFun = ":" ID "-\>" ID;
lexical ID = @category="Variable"
Expand Down

0 comments on commit 0e3a1f7

Please sign in to comment.