X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=tests%2Fregression.tc;h=cdad8315c69aec0b073e782755d30ae295679df6;hp=28ca476e643fa113eaa2774b4de6801107319c07;hb=225993309e6183afa9a88fc13d39df56be54b992;hpb=0ab024f487647f99eb000345c29c2f8e9b52a200 diff --git a/tests/regression.tc b/tests/regression.tc index 28ca476..cdad831 100644 --- a/tests/regression.tc +++ b/tests/regression.tc @@ -20,6 +20,22 @@ //} testcase { + input "aaaaa"; + s = A + A = "a" s &~ "a" A + | "a" A &~ "a" S +} + +testcase { + input "a"; + output "yes:{}"; + s = A + A = "a" s &~ "a" A + | "a" A &~ "a" S + | () +} + +testcase { input "ab c"; output "1:{{a b} {c}}"; @@ -265,65 +281,65 @@ testcase { q = q:: [a-z]++ } -//testcase { -// -// input " -// -// -// -// while x>0 -// while y>0 -// foo() -// bar() -// -// -// while x>0 -// while y>0 -// foo() -// bar() -// -// -// -//"; -// output "smt:{while:{>:{{x} {0}} while:{>:{{y} {0}} sbb:{{f o o} {b a r}}}} while:{>:{{x} {0}} sbb:{while:{>:{{y} {0}} {f o o}} {b a r}}}}"; -// -//indent ! = ww -//outdent ! = " " outdent " " -// | " " (~[]*) "\n" -// -//w ! = " " | "\n" | "\r" -//ws ! = w* -//ww ! = sp* -//sp ! = " " -//any ! = ~[]* -// -//s = ws statement ws statement ws => smt -// -//block = "\n" indent blockBody -// &~ "\n" outdent ~[\ ] ~[]* -// -//blockBody = statement -// > statement ws blockBody => "sbb" -// -//statement = call -// | ^"while" expr block /ws -// -//expr = ident -// | call -// | expr ^">" expr /ws -// | num -// -//call = expr "()" /ws -// -//num = [0-9]++ -// -//ident = [a-z]++ &~ keyword -//keyword = "if" | "then" | "else" | "while" -// -// -// -//} -// +testcase { + + input " + + + + while x>0 + while y>0 + foo() + bar() + + + while x>0 + while y>0 + foo() + bar() + + + +"; + output "smt:{while:{>:{{x} {0}} while:{>:{{y} {0}} sbb:{{f o o} {b a r}}}} while:{>:{{x} {0}} sbb:{while:{>:{{y} {0}} {f o o}} {b a r}}}}"; + +indent = ww +outdent = " " outdent " " + | " " (~[]*) "\n" + +w = " " | "\n" | "\r" +ws = w* +ww = sp* +sp = " " +any = ~[]* + +s = smt:: !ws statement !ws statement !ws + +block = !"\n" !indent blockBody + &~ !"\n" (" " !outdent " ") !(~[\ ]) !(~[]*) + +blockBody = statement + > sbb:: statement ws blockBody + +statement = call + | ^"while" expr block /ws + +expr = ident + | call + | expr ^">" expr /ws + | num + +call = expr "()" /ws + +num = [0-9]++ + +ident = [a-z]++ &~ keyword +keyword = "if" | "then" | "else" | "while" + + + +} + testcase { @@ -348,13 +364,27 @@ testcase { s = Expr Expr = [0-9]++ - | Plus:: left:Expra "+" right:Expr + | Plus:: (left::Expra) "+" (right::Expr) Expra = Foo:: ("a" | "b") } testcase { input "aaaaa"; - s = top:: z q:"a"* z + output "top:{a q:{{a a a}} a}"; + s = top:: z (q::"a"*) z z = a:: "a" -} \ No newline at end of file +} + +testcase { + input "if (x) if (y) z else q"; + output "if:{ident:{{x}} else:{if:{ident:{{y}} then:{ident:{{z}}}} ident:{{q}}}}"; + + s = Expr + Expr = if:: "if" "(" Expr ")" IfBody /ws + | ident:: [a-z]++ + IfBody = else:: Expr "else" Expr /ws + | then:: Expr &~ (~[]* "else" !Expr /ws) + ws = [ ]** +} +