Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XBGF transformation framework redone for Rascal: first setup
- Loading branch information
1 parent
8953e20
commit c9c1433
Showing
8 changed files
with
716 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
all: | ||
echo "Use Rascal" | ||
|
||
build: | ||
make clean | ||
cp ../../topics/convergence/xbgf/*/xbgf/*.xbgf tests/xbgf/ | ||
cp ../../topics/transformation/xbgf/tests/*.xbgf tests/xbgf/ | ||
|
||
check: | ||
echo "Validating input files..." | ||
ls -1 tests/xbgf/*.xbgf | xargs -n1 ../tools/validate xbgf | ||
echo "Validating output files..." | ||
ls -1 res/xbgf-res/*.xbgf | xargs -n1 ../tools/validate xbgf | ||
|
||
clean: | ||
rm -f tests/*/*.xbgf |
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,37 @@ | ||
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI} | ||
@doc{This simple program reads is the whole test suite for XBGF from the corresponding SLPS directory | ||
and generates a Rascal file that contains identically behaving test functions which can be invoked with | ||
:test | ||
command.} | ||
module Sync | ||
|
||
import String; | ||
import IO; | ||
import io::ReadBGF; | ||
import io::ReadXBGF; | ||
|
||
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} | ||
'@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI} | ||
'module transform::XBGFTest | ||
' | ||
'import syntax::BGF; | ||
'import syntax::XBGF; | ||
'import transform::XBGF; | ||
' | ||
'"+replaceAll(buffer,"import","\\import")); | ||
} | ||
|
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,55 @@ | ||
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI} | ||
module normal::BGF | ||
|
||
import syntax::BGF; | ||
|
||
public BGFGrammar normalise(grammar (list[str] roots, list[BGFProduction] prods)) | ||
= grammar (roots, [normalise(p) | p <- prods]); | ||
|
||
public BGFProduction normalise(production (str label, str lhs, BGFExpression rhs)) | ||
= production (label, lhs, normalise(rhs)); | ||
|
||
public BGFExpression normalise(BGFExpression e) | ||
{ | ||
// Algebraic normalisations; TODO: others needed? | ||
return innermost visit(e) | ||
{ | ||
case sequence([]) => epsilon() | ||
case sequence([BGFExpression e]) => e | ||
case choice([]) => empty() | ||
case choice([BGFExpression e]) => 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]) | ||
}; | ||
} | ||
|
||
public BGFGrammar tw(BGFExpression e) | ||
{ | ||
return grammar([],[production("","foo",e)]); | ||
} | ||
|
||
test bool n1() {return normalise(tw(sequence([])))==tw(epsilon());} | ||
test bool n2() {return normalise(tw(sequence([terminal("1")])))==tw(terminal("1"));} | ||
test bool n3() {return normalise(tw(choice([])))==tw(empty());} | ||
test bool n4() {return normalise(tw(choice([terminal("1")])))==tw(terminal("1"));} | ||
test bool n5() {return normalise(tw(optional(epsilon())))==tw(epsilon());} | ||
test bool n6() {return normalise(tw(plus(epsilon())))==tw(epsilon());} | ||
test bool n7() {return normalise(tw(star(epsilon())))==tw(epsilon());} | ||
test bool n8() {return normalise(tw(sequence([terminal("1"),sequence([terminal("2"),terminal("3")])]))) | ||
==tw(sequence([terminal("1"),terminal("2"),terminal("3")]));} | ||
test bool n9() {return normalise(tw(sequence([sequence([terminal("1"),terminal("2")]),terminal("3")]))) | ||
==tw(sequence([terminal("1"),terminal("2"),terminal("3")]));} | ||
test bool n10(){return normalise(tw(sequence([terminal("1"),epsilon(),terminal("2"),epsilon()]))) | ||
==tw(sequence([terminal("1"),terminal("2")]));} | ||
test bool n11(){return normalise(tw(choice([terminal("1"),choice([terminal("2"),terminal("3")])]))) | ||
==tw(choice([terminal("1"),terminal("2"),terminal("3")]));} | ||
test bool n12(){return normalise(tw(choice([choice([terminal("1"),terminal("2")]),terminal("3")]))) | ||
==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")]));} | ||
|
Oops, something went wrong.