Skip to content

Commit

Permalink
implosion done, modulo comments (will decide later)
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Oct 2, 2012
1 parent b8ca9d0 commit 475e1a7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
4 changes: 4 additions & 0 deletions topics/mega/src/MegaADT.rsc
Expand Up @@ -26,4 +26,8 @@ data MegaRelation
| descriptionOf(str x, str y)
| definitionOf(str x, str y)
| mapsTo(str f, str x, str y)
| inputOf(str x, str y)
| hasOutput(str x, str y)
| domainOf(str x, str y)
| hasRange(str x, str y)
;
6 changes: 3 additions & 3 deletions topics/mega/src/MegaGrammar.rsc
Expand Up @@ -23,7 +23,7 @@ syntax MegaEntity
;
syntax MegaArtifact = "Artifact" | "File" | "Language" | "Technology" | "Fragment" | "ObjectGraph" | "Program" | "Library";
syntax MegaRel
= ID MegaBin ID
= ID MegaBin ID
| ID MegaFun
| ID "(" ID ")" "|-\>" ID
;
Expand All @@ -37,14 +37,14 @@ syntax MegaBin
| ( "=\>" | "realizationOf" | "descriptionOf" | "definitionOf" )
;
syntax MegaFun = ":" ID "-\>" ID;
lexical ID = //@category="Constant"
lexical ID = @category="Variable"
([a-zA-z] [a-zA-Z0-9_]* !>> [a-zA-Z0-9_]) \ Keywords ;
keyword Keywords
= "megamodel" | "include" | "local" | "variable" | "Artifact" | "File" | "Language" | "Technology" | "Fragment" | "ObjectGraph" | "Program" | "Library"
| "subsetOf" | "elementOf" | "partOf" | "correspondsTo" | "dependsOn" | "refersTo" | "conformsTo" | "realizationOf" | "descriptionOf" | "definitionOf"
;
syntax STRING = [\"] ![\"]* [\"]; //"
lexical MegaDesc = "{-" MegaDescEl* s "-}";
lexical MegaDesc = @category="Comment" "{-" MegaDescEl* s "-}";
lexical MegaDescEl = ![\-] | [\-] !>> [}];

layout L = LAYOUT* !>> [\ \t\n\r]; // !>> "--";
Expand Down
57 changes: 28 additions & 29 deletions topics/mega/src/MegaImplode.rsc
Expand Up @@ -13,7 +13,7 @@ public void main(list[str] argv)
{
// iprintln(mapmegal(parse(#MegaModel,trim(readFile(|cwd:///../tests/technology.megal|)))));
//iprintln(mapmegal(parse(#MegaModel,trim(readFile(|cwd:///../tests/read.megal|)))));
iprintln(mapmegal(parse(#MegaModel,trim(readFile(|project://megal/tests/technology.megal|)))));
iprintln(mapmegal(parse(#MegaModel,trim(readFile(|project://megal/tests/deserialization.megal|)))));
}

AMegaModel mapmegal((MegaModel)`<MegaHeader h><MegaInclude* ins><MegaDecl+ ds>`) = makemegal("<h.name>","",ins,ds);
Expand All @@ -25,12 +25,19 @@ AMegaModel makemegal(str name, str desc, MegaInclude* ins, MegaDecl+ ds)

list[str] collectIncludes(MegaInclude* ins) = ["<i.name>" | MegaInclude i <- ins];
list[MegaDeclaration] collectDecls(MegaDecl+ ds) = [*mapdecl(d) | MegaDecl d <- ds];
list[MegaRelation] collectRels(MegaDecl+ ds) = [];
list[MegaRelation] collectRels(MegaDecl+ ds) = [*maprel(d) | MegaDecl d <- ds];

list[MegaDeclaration] mapdecl((MegaDecl)`<MegaModifier? mm><MegaEntity e><MegaDot d>`) = [map1decl(e,mapmod(mm),"<e.id>")];
//list[MegaDeclaration] mapdecl((MegaDecl)`<MegaModifier? mm><MegaEntity e><MegaDot d>`) = [map2decl(mapmod(mm),"<e.id>")];
default list[MegaDeclaration] mapdecl(MegaDecl d) = [];

list[MegaRelation] maprel((MegaDecl)`<MegaModifier? _><MegaArtifact _><MaybePlus plus><ID x><MegaBin b><ID y><MegaDot d>`) = [map1rel("<b>","<x>","<y>")];
list[MegaRelation] maprel((MegaDecl)`<MegaModifier? _>Function<MaybePlus plus><ID x>:<ID y>-><ID z><MegaDot d>`) = [domainOf("<y>","<x>"),hasRange("<x>","<z>")];
list[MegaRelation] maprel((MegaDecl)`<ID x><MegaBin b><ID y><MegaDot d>`) = [map1rel("<b>","<x>","<y>")];
list[MegaRelation] maprel((MegaDecl)`<ID x>:<ID y>-><ID z><MegaDot d>`) = [domainOf("<y>","<x>"),hasRange("<x>","<z>")];
list[MegaRelation] maprel((MegaDecl)`<ID x>(<ID y>)|-><ID z><MegaDot d>`) = [inputOf("<y>","<x>"),hasOutput("<x>","<z>")];
default list[MegaRelation] maprel(MegaDecl d) = [];

MegaMod mapmod(MegaModifier? m)
{
switch("<m>")
Expand All @@ -48,6 +55,25 @@ bool isplus((MaybePlus)`+`) = true;
bool isplus((MaybePlus)``) = false;
default bool isplus(MaybePlus _) = false; // insurance

MegaRelation map1rel("\<", str x, str y) = subsetOf(x,y);
MegaRelation map1rel("subsetOf", str x, str y) = subsetOf(x,y);
MegaRelation map1rel(":", str x, str y) = elementOf(x,y);
MegaRelation map1rel("elementOf", str x, str y) = elementOf(x,y);
MegaRelation map1rel("@", str x, str y) = partOf(x,y);
MegaRelation map1rel("partOf", str x, str y) = partOf(x,y);
MegaRelation map1rel("=", str x, str y) = correspondsTo(x,y);
MegaRelation map1rel("correspondsTo", str x, str y) = correspondsTo(x,y);
MegaRelation map1rel("~\>", str x, str y) = refersTo(x,y);
MegaRelation map1rel("dependsOn", str x, str y) = dependsOn(x,y);
MegaRelation map1rel("refersTo", str x, str y) = refersTo(x,y);
MegaRelation map1rel("-|", str x, str y) = conformsTo(x,y);
MegaRelation map1rel("conformsTo", str x, str y) = conformsTo(x,y);
MegaRelation map1rel("=\>", str x, str y) = definitionOf(x,y);
MegaRelation map1rel("realizationOf", str x, str y) = realizationOf(x,y);
MegaRelation map1rel("descriptionOf", str x, str y) = descriptionOf(x,y);
MegaRelation map1rel("definitionOf", str x, str y) = definitionOf(x,y);
default MegaRelation map1rel(str b, str x, str y) = subsetOf(x,y); // no error report

MegaDeclaration map1decl((MegaEntity)`<MegaArtifact a><MaybePlus plus><ID x><MegaBin _><ID _>`,MegaMod m, str id)
= map1decl((MegaEntity)`<a><plus><x>`, m, id);

Expand All @@ -68,30 +94,3 @@ MegaDeclaration map1decl((MegaEntity)`<MegaArtifact a><MaybePlus plus><ID _>`,Me
}
MegaDeclaration map1decl((MegaEntity)`Function<MaybePlus plus><ID _><MegaFun? _>`,MegaMod m, str id) = function(m,id,isplus(plus)); //"
default MegaDeclaration map1decl(MegaEntity e,MegaMod m, str id) = println("ERROR in <e>");

// data AMegaModel = megamodel(str name, str desc, list[str] incs, list[MegaDeclaration] decls, list[MegaRelation] rels);
// data MegaDeclaration
// = artifact(MegaMod m, str id, bool plus)
// | file(MegaMod m, str id, bool plus)
// | language(MegaMod m, str id, bool plus)
// | technology(MegaMod m, str id, bool plus)
// | fragment(MegaMod m, str id, bool plus)
// | objectgraph(MegaMod m, str id, bool plus)
// | program(MegaMod m, str id, bool plus)
// | library(MegaMod m, str id, bool plus)
// | function(MegaMod m, str id, bool plus)
// ;
// data MegaMod = local() | variable() | nomod();
// data MegaRelation
// = subsetOf(str x, str y)
// | elementOf(str x, str y)
// | partOf(str x, str y)
// | correspondsTo(str x, str y)
// | dependsOn(str x, str y)
// | refersTo(str x, str y)
// | conformsTo(str x, str y)
// | realizationOf(str x, str y)
// | descriptionOf(str x, str y)
// | definitionOf(str x, str y)
// | mapsTo(str f, str x, str y)
// ;

0 comments on commit 475e1a7

Please sign in to comment.