Skip to content

Commit

Permalink
deLayering is implemented as a grammar mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Jul 8, 2012
1 parent f974d30 commit 2b976f1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 10 additions & 0 deletions shared/rascal/src/analyse/Layers.rsc
Expand Up @@ -3,13 +3,19 @@ module analyse::Layers

import syntax::BGF;
import syntax::XBGF;
import syntax::CBGF;
import io::ReadBGF;
import lib::Rascalware;
import analyse::Metrics;
import normal::BGF;
import transform::XBGF;
import transform::CBGF;
import export::BNF;
import Relation;
import IO;

CBGFSequence removeLayers(rel[str,str] layers, BGFGrammar g)
= [unite_splitN(l<0>, prodsOfN( l<1>, g.prods), globally()) | l <- layers];

rel[str,str] detectLayers(BGFGrammar g)
{
Expand Down Expand Up @@ -56,6 +62,10 @@ public void main()
println("Analysing <src>...");
rel[str,str] layers = detectLayers(g);
if(!isEmpty(layers))
{
println("Found <layers>");
iprintln(removeLayers(layers,g));
println(pp(transform(forward(removeLayers(layers,g)),g)));
}
}
}
6 changes: 3 additions & 3 deletions shared/rascal/src/converge/PureGuided.rsc
Expand Up @@ -21,11 +21,11 @@ import Relation;
list[str] sources =
//["antlr","dcg","ecore","emf","jaxb","om","python","rascal-a","rascal-c","sdf","txl","xsd"];
//["emf","jaxb","om","rascal-c","sdf","xsd","txl"];
["python"];
["antlr"];
// atom/expr: antlr, dcg
// arg/string: ecore, rascal-a
// good: emf, jaxb, om, rascal-c, sdf, xsd, txl
// multiroot: python
// multiroot & atom/expr: python

BGFProduction getSingleProd(str n, BGFProdList ps)
{
Expand Down Expand Up @@ -120,7 +120,7 @@ set[NameMatch] nominalMatch(NameMatch known, BGFProdList mps, BGFProdList sps)
truenm = tryMatch(nm,known,p1,mps,p2,sps);
//println("Got <pp(truenm)> with <pp(known)>...");
if (!isEmpty(invert(truenm) o known) || !isEmpty(truenm o invert(known)))
println("Naming conflict, reconsider.");
println("Naming conflict: <pp(truenm)> vs <pp(known)>, reconsider.");
else
{
newmatch = nominalMatch(known + truenm, mps - p1, assumeRenamings(sps - p2, truenm));
Expand Down
4 changes: 2 additions & 2 deletions shared/rascal/src/transform/CBGF.rsc
Expand Up @@ -68,7 +68,7 @@ XBGFCommand forward(unite_splitN(str x, list[BGFProduction] ps, XBGFScope w))
{
// TODO: w
// TODO: check that x != y
if ({str y} := analyse::Metrics::definedNs(ps)) return unite(x,y);
if ({str y} := analyse::Metrics::definedNs(ps)) return unite(y,x);
else throw "<ps> must concern one nonterminal";
}
XBGFCommand forward(unlabel_designate(production(str l,_,_))) = unlabel(l);
Expand Down Expand Up @@ -130,7 +130,7 @@ XBGFCommand reverse(splitN_unite(str x, list[BGFProduction] ps, XBGFScope w))
{
// TODO: w
// TODO: check that x != y
if ({str y} := analyse::Metrics::definedNs(ps)) return unite(x,y);
if ({str y} := analyse::Metrics::definedNs(ps)) return unite(y,x);
else throw "<ps> must concern one nonterminal";
}
XBGFCommand reverse(splitT_concatT(str x, list[str] ys, XBGFScope w)) = splitT(x,ys,w);
Expand Down

0 comments on commit 2b976f1

Please sign in to comment.