Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reimplement unchain mutation in Rascal
- Loading branch information
1 parent
5e81ccc
commit fdb3297
Showing
2 changed files
with
18 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI} | ||
module mutate::InlineChains | ||
|
||
import IO; | ||
import syntax::BGF; | ||
import export::BNF; | ||
|
||
public BGFGrammar unchain_m(BGFGrammar g) | ||
{ | ||
ps = g.prods; | ||
for (tp:production(_,_,nonterminal(chained)) <- [p | p:production(_,_,nonterminal(x)) <- g.prods]) | ||
{ | ||
myprods = [bp | bp:production(_,chained,_) <- ps]; | ||
if ([production(_,_,rhs)] := myprods) | ||
ps = ps + production(tp.label,tp.lhs,rhs) - myprods - tp; | ||
} | ||
return grammar(g.roots,ps); | ||
} |