Skip to content

Commit

Permalink
MegaParser is becoming a testing framework for the rest
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Oct 3, 2012
1 parent 9f8808b commit 7c92e2a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
8 changes: 6 additions & 2 deletions topics/mega/src/MegaParser.rsc
Expand Up @@ -2,6 +2,8 @@
module MegaParser

import structure::MegaGrammar;
import structure::MegaADT;
import io::ReadMegaL;
import Ambiguity;
import ParseTree;
import String;
Expand All @@ -12,7 +14,9 @@ public void main(list[str] args)
loc base = |cwd:///../tests|;
for (f <- listEntries(base), endsWith(f,".megal"))
{
println("Parsing <base+f>...");
parse(#MegaModel,base+f);
println("Getting a parse tree of <f>...");
readPT(base+f);
println("Getting an abstract syntax tree of <f>...");
readAST(base+f);
}
}
@@ -1,21 +1,10 @@
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
module MegaImplode
module backend::MegaImplode

import structure::MegaADT;
import structure::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|)))));
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);
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("","",[],[],[]);
Expand Down
13 changes: 13 additions & 0 deletions topics/mega/src/io/ReadMegaL.rsc
@@ -0,0 +1,13 @@
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
module io::ReadMegaL

import structure::MegaGrammar;
import structure::MegaADT;
import backend::MegaImplode;
import ParseTree;
import String;
import IO;

public MegaModel readPT(loc f) = parse(#MegaModel,trim(readFile(f)));

public AMegaModel readAST(loc f) = backend::MegaImplode::mapmegal(readPT(f));

0 comments on commit 7c92e2a

Please sign in to comment.