Skip to content

Commit

Permalink
refactored the grammar so that comments are easily accessible; ADT fo…
Browse files Browse the repository at this point in the history
…r megamodels done; mapping parse trees to ASTs started
  • Loading branch information
grammarware committed Oct 2, 2012
1 parent fd7f3ed commit 9790f98
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 22 deletions.
29 changes: 29 additions & 0 deletions topics/mega/src/MegaADT.rsc
@@ -0,0 +1,29 @@
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
module MegaADT

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)
;
21 changes: 10 additions & 11 deletions topics/mega/src/MegaGrammar.rsc
@@ -1,13 +1,13 @@
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
module MegaGrammar

start syntax MegaModel = MegaDesc? MegaHeader MegaInclude* MegaDecl+ L;
syntax MegaHeader = "megamodel" MegaURI ".";
start syntax MegaModel = MegaDesc? MegaHeader MegaInclude* MegaDecl+;
syntax MegaHeader = "megamodel" MegaURI name MegaDot;
syntax MegaURI = {ID "/"}+;
syntax MegaInclude = "include" MegaURI ".";
syntax MegaInclude = "include" MegaURI name MegaDot;
syntax MegaDecl
= MegaModifier? MegaEntity "."
| MegaRel "."
= MegaModifier? MegaEntity MegaDot
| MegaRel MegaDot
;
syntax MegaModifier = "local" | "variable" ;
syntax MegaEntity
Expand Down Expand Up @@ -39,11 +39,10 @@ keyword Keywords
| "subsetOf" | "elementOf" | "partOf" | "correspondsTo" | "dependsOn" | "refersTo" | "conformsTo" | "realizationOf" | "descriptionOf" | "definitionOf"
;
syntax STRING = [\"] ![\"]* [\"]; //"
lexical MegaDesc = "{-" MegaDescEl* "-}";
lexical MegaDesc = "{-" MegaDescEl* s "-}";
lexical MegaDescEl = ![\-] | [\-] !>> [}];

layout L = LAYOUT* !>> [\ \t\n\r] !>> "--";
lexical LAYOUT
= [\ \t\n\r]
| @category="Comment" "--" ![\n]* $
;
layout L = LAYOUT* !>> [\ \t\n\r]; // !>> "--";
lexical LAYOUT = [\ \t\n\r];
syntax MegaDot = "." MegaComment? ;
lexical MegaComment = @category="Comment" "--" ![\n]* $ ;
55 changes: 55 additions & 0 deletions topics/mega/src/MegaImplode.rsc
@@ -0,0 +1,55 @@
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
module MegaImplode

import MegaADT;
import MegaGrammar;
import IO;
import ParseTree;
import String;

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|)))));
}

AMegaModel mapmegal((MegaModel)`<MegaHeader h><MegaInclude* ins><MegaDecl+ ds>`) = makemegal("<h.name>","",ins,ds);
AMegaModel mapmegal((MegaModel)`<MegaDesc d><MegaHeader h><MegaInclude* ins><MegaDecl+ ds>`) = makemegal("<h.name>",trim("<d.s>"),ins,ds);
default AMegaModel mapmegal(MegaModel m) = megamodel("","",[],[],[]);

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[MegaRelation] collectRels(MegaDecl+ ds) = [];

// 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)
// ;
6 changes: 0 additions & 6 deletions topics/mega/src/MegaParser.rsc
Expand Up @@ -7,12 +7,6 @@ import ParseTree;
import String;
import IO;

// public void main()
// {
// registerLanguage("MegaL", "megal", MegaModel(str input, loc org) {return parse(#MegaModel, input, org);});
// println("MegaL is registered");
// }

public void main(list[str] args)
{
loc base = |cwd:///../tests|;
Expand Down
5 changes: 0 additions & 5 deletions topics/mega/src/Plugin.rsc
Expand Up @@ -12,8 +12,3 @@ public void main()
registerLanguage("MegaL", "megal", MegaModel(str input, loc org) {return parse(#MegaModel, input, org);});
println("MegaL is registered");
}

public void t()
{
parse(#MegaModel,|project://megal/tests/annotation.megal|);
}

0 comments on commit 9790f98

Please sign in to comment.