Skip to content

Commit

Permalink
implosion almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Oct 2, 2012
1 parent 9790f98 commit b8ca9d0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
2 changes: 1 addition & 1 deletion topics/mega/src/MegaADT.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data MegaDeclaration
| 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)
| 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)
Expand Down
14 changes: 10 additions & 4 deletions topics/mega/src/MegaGrammar.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ syntax MegaDecl
| MegaRel MegaDot
;
syntax MegaModifier = "local" | "variable" ;
//// VVZ: The original MegaL definition used comma-separation lists
// syntax MegaEntity
// = MegaArtifact MaybePlus {MegaIdsBin ","}+
// | "Function" MaybePlus {MegaIdsFun ","}+
// ;
// syntax MegaIdsBin = ID (MegaBin ID)?;
// syntax MegaIdsFun = ID MegaFun?;
syntax MegaEntity
= MegaArtifact "+"? {MegaIdsBin ","}+
| "Function" "+"? {MegaIdsFun ","}+
= MegaArtifact MaybePlus ID id (MegaBin ID)?
| "Function" MaybePlus ID id MegaFun?
;
syntax MegaIdsBin = ID (MegaBin ID)?;
syntax MegaIdsFun = ID MegaFun?;
syntax MegaArtifact = "Artifact" | "File" | "Language" | "Technology" | "Fragment" | "ObjectGraph" | "Program" | "Library";
syntax MegaRel
= ID MegaBin ID
Expand Down Expand Up @@ -46,3 +51,4 @@ layout L = LAYOUT* !>> [\ \t\n\r]; // !>> "--";
lexical LAYOUT = [\ \t\n\r];
syntax MegaDot = "." MegaComment? ;
lexical MegaComment = @category="Comment" "--" ![\n]* $ ;
syntax MaybePlus = "+"?;
48 changes: 45 additions & 3 deletions topics/mega/src/MegaImplode.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public void main() = main([]);
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(|cwd:///../tests/read.megal|)))));
iprintln(mapmegal(parse(#MegaModel,trim(readFile(|project://megal/tests/technology.megal|)))));
}

AMegaModel mapmegal((MegaModel)`<MegaHeader h><MegaInclude* ins><MegaDecl+ ds>`) = makemegal("<h.name>","",ins,ds);
Expand All @@ -23,10 +24,51 @@ AMegaModel makemegal(str name, str desc, MegaInclude* ins, MegaDecl+ ds)
= megamodel(name,desc,collectIncludes(ins),collectDecls(ds),collectRels(ds));

list[str] collectIncludes(MegaInclude* ins) = ["<i.name>" | MegaInclude i <- ins];
// list[str] collectIncludes(MegaInclude* ins) = [];
list[MegaDeclaration] collectDecls(MegaDecl+ ds) = [];
list[MegaDeclaration] collectDecls(MegaDecl+ ds) = [*mapdecl(d) | MegaDecl d <- ds];
list[MegaRelation] collectRels(MegaDecl+ 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) = [];
MegaMod mapmod(MegaModifier? m)
{
switch("<m>")
{
case "local": return local();
case "variable": return variable();
default: return nomod();
}
}
//MegaMod mapmod((MegaModifier?)`local`) = local();
//MegaMod mapmod((MegaModifier?)`variable`) = variable();
//MegaMod mapmod((MegaModifier?)``) = nomod();
bool isplus((MaybePlus)`+`) = true;
bool isplus((MaybePlus)``) = false;
default bool isplus(MaybePlus _) = false; // insurance
MegaDeclaration map1decl((MegaEntity)`<MegaArtifact a><MaybePlus plus><ID x><MegaBin _><ID _>`,MegaMod m, str id)
= map1decl((MegaEntity)`<a><plus><x>`, m, id);
MegaDeclaration map1decl((MegaEntity)`<MegaArtifact a><MaybePlus plus><ID _>`,MegaMod m, str id)
{
switch("<a>")
{
case "Artifact": return artifact(m,id,isplus(plus));
case "File": return file(m,id,isplus(plus));
case "Language": return language(m,id,isplus(plus));
case "Technology": return technology(m,id,isplus(plus));
case "Fragment": return fragment(m,id,isplus(plus));
case "ObjectGraph": return objectGraph(m,id,isplus(plus));
case "Program": return program(m,id,isplus(plus));
case "Library": return library(m,id,isplus(plus));
default: println("ERROR in <a>.");
}
}
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)
Expand Down

0 comments on commit b8ca9d0

Please sign in to comment.