Skip to content

Commit

Permalink
polishing refactorings of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Jan 14, 2013
1 parent fa8c55c commit 3413ed2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion shared/rascal/src/transform/NegotiatedXBGF.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ set[str] adviseFreshNonterminal(str x, set[str] nts)
// expr -> expr1
while ("<x><cx>" in nts) cx+=1;
adv += "<x><cx>";
cx = 0;
// expr -> expr_
while (s in nts) s += "_";
adv += s;
Expand Down
4 changes: 2 additions & 2 deletions shared/rascal/src/transform/library/Factoring.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import transform::Results;
import transform::library::Util;
import transform::library::Brutal;

XBGFResult runFactor(BGFExpression e1, BGFExpression e2, XBGFScope w, g)
XBGFResult runFactor(BGFExpression e1, BGFExpression e2, XBGFScope w, BGFGrammar g)
{
e3 = normalise(transform::library::Factoring::makeDistributed(e1));
e4 = normalise(transform::library::Factoring::makeDistributed(e2));
Expand All @@ -26,7 +26,7 @@ XBGFResult runDistribute(XBGFScope w, BGFGrammar g)
return <ok(),grammar(g.roots, ps1 + normalise([makeDistributed(p) | p <- ps2]) + ps3)>;
}
BGFProduction makeDistributed(production(str l, str x, BGFExpression e)) = production(l, x, makeDistributed(e));
BGFProduction makeDistributed(BGFProductuion p) = production(p.label, p.lhs, makeDistributed(p.rhs));
BGFExpression makeDistributed(BGFExpression e1)
{
Expand Down
10 changes: 5 additions & 5 deletions shared/rascal/src/transform/library/Folding.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import transform::Results;
import transform::library::Util;
import transform::library::Brutal;

XBGFResult runExtract(production(str l, str x, BGFExpression rhs), XBGFScope w, grammar(rs,ps))
XBGFResult runExtract(production(str l, str x, BGFExpression rhs), XBGFScope w, BGFGrammar g)
{
if (x in definedNs(ps))
if (x in definedNs(g.prods))
return <notFreshN(x),g>;
// TODO hard to check if rhs occurs in the grammar; it was somehow done in xbgf1.pro
XBGFResult rep = transform::library::Brutal::runReplace(rhs,nonterminal(x),w,grammar(rs,ps));
XBGFResult rep = transform::library::Brutal::runReplace(rhs,nonterminal(x),w,g);
if (ok() !:= rep.r) return rep;
else return <ok(),grammar(rep.g.roots,rep.g.prods + production(l,x,rhs))>;
}
Expand Down Expand Up @@ -44,13 +44,13 @@ XBGFResult runUnfold(str x, XBGFScope w, BGFGrammar g)
}

// Liberal forms of folding
XBGFResult runDowngrade(BGFProduction p1, BGFProduction p2, grammar(rs, ps))
XBGFResult runDowngrade(BGFProduction p1, BGFProduction p2, BGFGrammar g)
{
if (/marked(nonterminal(str x)) := p1)
if (production(str l,x,BGFExpression e) := p2)
{
p3 = visit(p1){case marked(_) => e};
return <ok(),grammar(rs,replaceP(ps,unmark(p1),normalise(p3)))>;
return <ok(),grammar(g.roots,replaceP(g.prods,unmark(p1),normalise(p3)))>;
}
else
return <problemProd2("Production rules do not agree on nonterminal",p1,p2),g>;
Expand Down
4 changes: 2 additions & 2 deletions shared/rascal/src/transform/library/Util.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public set[str] allTs(list[BGFProduction] ps) = {s | /terminal(str s) := ps};
public set[str] usedNs(list[BGFProduction] ps) = {s | /nonterminal(str s) := ps};
public set[str] definedNs(list[BGFProduction] ps) = {s | production(_,str s,_) <- ps};

public list[BGFProduction] replaceP(list[BGFProduction] ps, p1, p2)
public list[BGFProduction] replaceP(list[BGFProduction] ps, BGFProduction p1, BGFProduction p2)
{
list[BGFProduction] ps2 = [];
for (p <- ps)
Expand All @@ -131,4 +131,4 @@ public list[BGFProduction] replaceP(list[BGFProduction] ps, p1, p2)
}

public bool inProds(BGFProduction p, []) = false;
public bool inProds(BGFProduction p, list[BGFProduction] ps) = eqP(normalise(p),normalise(ps[0])) || inProds(p,tail(ps));
public default bool inProds(BGFProduction p, list[BGFProduction] ps) = eqP(normalise(p),normalise(ps[0])) || inProds(p,tail(ps));
2 changes: 1 addition & 1 deletion shared/rascal/src/transform/library/Width.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bool narrowing(plus(e),e) = true;
bool narrowing(optional(e),e) = true;
default bool narrowing(_,_) = false;

XBGFResult runNarrow(BGFExpression e1, BGFExpression e2, XBGFScope w, g)
XBGFResult runNarrow(BGFExpression e1, BGFExpression e2, XBGFScope w, BGFGrammar g)
{
if (!narrowing(e1,e2))
return <problemExpr2("Expressions are not in narrowing relation.",e1,e2),g>;
Expand Down

0 comments on commit 3413ed2

Please sign in to comment.