Skip to content

Commit

Permalink
abridge, abstractize/concretize, addV/removeV, addH/removeH, anonymiz…
Browse files Browse the repository at this point in the history
…e/deanonymize, appear/disappear, inject/project are (re)done
  • Loading branch information
grammarware committed Jun 1, 2012
1 parent c9c1433 commit a3da9b3
Show file tree
Hide file tree
Showing 19 changed files with 593 additions and 370 deletions.
23 changes: 11 additions & 12 deletions shared/rascal/src/Sync.rsc
Expand Up @@ -14,24 +14,23 @@ public void main()
{
loc base = |home:///projects/slps/topics/transformation/xbgf/tests|;
int cx = 1;
str buffer = "";
for (f <- listEntries(base), endsWith(f,".xbgf"))
{
xbgf = readXBGF(base+f);
bgf = readBGF(base+replaceLast(f,".xbgf",".bgf"));
bl = readBGF(base+replaceLast(f,".xbgf",".baseline"));
buffer += "test bool x<cx>() { return transform(<xbgf>,<bgf>)==<bl>; }\n";
cx+=1;
}
writeFile(|project://slps/src/transform/XBGFTest.rsc|,
"@contributor{Super Awesome Automated XBGF Test Suite Synchroniser}
str buffer = "@contributor{Super Awesome Automated XBGF Test Suite Synchroniser}
'@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
'module transform::XBGFTest
'
'import syntax::BGF;
'import syntax::XBGF;
'import transform::XBGF;
'
'"+replaceAll(buffer,"import","\\import"));
'";
for (f <- listEntries(base), endsWith(f,".xbgf"))
{
xbgf = readXBGF(base+f);
bgf = readBGF(base+replaceLast(f,".xbgf",".bgf"));
bl = readBGF(base+replaceLast(f,".xbgf",".baseline"));
buffer += "test bool test_<replaceLast(f,".xbgf","")>() { return transform(<xbgf>,<bgf>)==<bl>; }\n";
cx+=1;
}
writeFile(|project://slps/src/transform/XBGFTest.rsc|, buffer);
}

2 changes: 1 addition & 1 deletion shared/rascal/src/io/ReadXBGF.rsc
Expand Up @@ -49,7 +49,7 @@ XBGFCommand mapxbgf(Node el)
case element(_,"fold",[element(none(),"nonterminal",[charData(str s)])]): return fold(s,globally());
case element(_,"fold",[element(none(),"nonterminal",[charData(str s)]),w]): return fold(s,mapcontext(w));
case element(_,"horizontal",[w]): return horizontal(mapcontext(w));
case element(_,"import",ps): return \import([mapprod(p) | p <- ps]);
case element(_,"import",ps): return importG([mapprod(p) | p <- ps]);
case element(_,"inject",[prod]): return inject(mapprod(prod));
case element(_,"inline",[charData(str s)]): return inline(s);
case element(_,"introduce",ps): return introduce([mapprod(p) | p <- ps]);
Expand Down
2 changes: 1 addition & 1 deletion shared/rascal/src/io/WriteXBGF.rsc
Expand Up @@ -51,7 +51,7 @@ Node xbgf2xml(XBGFCommand step)
case fold(str s,globally()): return element(namespace("xbgf","http://planet-sl.org/xbgf"),"fold",[element(none(),"nonterminal",[charData(s)])]);
case fold(str s, w): return element(namespace("xbgf","http://planet-sl.org/xbgf"),"fold",[element(none(),"nonterminal",[charData(s)]),element(none(),"in",[context2xml(w)])]);
case horizontal(w): return element(namespace("xbgf","http://planet-sl.org/xbgf"),"horizontal",[context2xml(w)]);
case \import(ps): return element(namespace("xbgf","http://planet-sl.org/xbgf"),"import",[prod2xml(p) | p <- ps]);
case importG(ps): return element(namespace("xbgf","http://planet-sl.org/xbgf"),"import",[prod2xml(p) | p <- ps]);
case inject(prod): return element(namespace("xbgf","http://planet-sl.org/xbgf"),"inject",[prod2xml(prod)]);
case inline(str s): return element(namespace("xbgf","http://planet-sl.org/xbgf"),"inline",[charData(s)]);
case introduce(ps): return element(namespace("xbgf","http://planet-sl.org/xbgf"),"introduce",[prod2xml(p) | p <- ps]);
Expand Down
13 changes: 8 additions & 5 deletions shared/rascal/src/normal/BGF.rsc
Expand Up @@ -21,10 +21,10 @@ public BGFExpression normalise(BGFExpression e)
case optional(epsilon()) => epsilon()
case plus(epsilon()) => epsilon()
case star(epsilon()) => epsilon()
case sequence([*L1,sequence(L),*L2]) => sequence(L1+L+L2)
case sequence([*L1,epsilon(),*L2]) => sequence(L1+L2)
case choice([*L1,choice(L),*L2]) => choice(L1+L+L2)
case choice([*L1,X1,*L2,X1,*L3]) => choice([*L1,X1,*L2,*L3])
case sequence([L1*,sequence(L),L2*]) => sequence(L1+L+L2)
case sequence([L1*,epsilon(),L2*]) => sequence(L1+L2)
case choice([L1*,choice(L),L2*]) => choice(L1+L+L2)
case choice([L1*,X1,L2*,X1,L3*]) => choice([*L1,X1,*L2,*L3])
};
}

Expand Down Expand Up @@ -52,4 +52,7 @@ test bool n12(){return normalise(tw(choice([choice([terminal("1"),terminal("2")]
==tw(choice([terminal("1"),terminal("2"),terminal("3")]));}
test bool n13(){return normalise(tw(choice([terminal("1"),terminal("2"),terminal("2"),terminal("3")])))
==tw(choice([terminal("1"),terminal("2"),terminal("3")]));}

test bool n14(){return normalise(production("","N",sequence([epsilon(),nonterminal("a"),nonterminal("b")])))
== production("","N",sequence([nonterminal("a"),nonterminal("b")]));}


2 changes: 1 addition & 1 deletion shared/rascal/src/syntax/XBGF.rsc
Expand Up @@ -30,7 +30,7 @@ data XBGFCommand =
| factor(BGFExpression e1, BGFExpression e2, XBGFContext w)
| fold(str x, XBGFContext w)
| horizontal(XBGFContext w)
| \import(list[BGFProduction] ps)
| importG(list[BGFProduction] ps)
| inject(BGFProduction p) // marked
| inline(str x)
| introduce(list[BGFProduction] ps)
Expand Down

0 comments on commit a3da9b3

Please sign in to comment.