Skip to content

Commit

Permalink
Fixed type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKlint committed Oct 4, 2024
1 parent 8c98557 commit 1a13702
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ module lang::rascalcore::grammar::tests::CharactersTests
import lang::rascalcore::grammar::definition::Characters;
import lang::rascalcore::check::AType;

test bool testFlip() = \new-char-class([range(2,2), range(1,1)]) == \char-class([range(1,2)]);
test bool testMerge() = \new-char-class([range(3,4), range(2,2), range(1,1)]) == \char-class([range(1,4)]);
test bool testEnvelop() = \new-char-class([range(10,20), range(15,20), range(20,30)]) == \char-class([range(10,30)]);
test bool testEnvelop2() = \new-char-class([range(10,20), range(10,19), range(20,30)]) == \char-class([range(10,30)]);
test bool testFlip() = \new-char-class([arange(2,2), arange(1,1)]) == \achar-class([arange(1,2)]);
test bool testMerge() = \new-char-class([arange(3,4), arange(2,2), arange(1,1)]) == \achar-class([arange(1,4)]);
test bool testEnvelop() = \new-char-class([arange(10,20), arange(15,20), arange(20,30)]) == \achar-class([arange(10,30)]);
test bool testEnvelop2() = \new-char-class([arange(10,20), arange(10,19), arange(20,30)]) == \achar-class([arange(10,30)]);

test bool testComp() = complement(\char-class([])) == \char-class([range(1,1114111)]);
test bool testComp2() = complement(\char-class([range(0,0)])) == \char-class([range(1,1114111)]);
test bool testComp3() = complement(\char-class([range(1,1)])) == \char-class([range(2,1114111)]);
test bool testComp4() = complement(\char-class([range(10,20), range(30,40)])) == \char-class([range(1,9),range(21,29),range(41,1114111)]);
test bool testComp5() = complement(\char-class([range(10,35), range(30,40)])) == \char-class([range(1,9),range(41,1114111)]);
test bool testComp() = complement(\achar-class([])) == \achar-class([arange(1,1114111)]);
test bool testComp2() = complement(\achar-class([arange(0,0)])) == \achar-class([arange(1,1114111)]);
test bool testComp3() = complement(\achar-class([arange(1,1)])) == \achar-class([arange(2,1114111)]);
test bool testComp4() = complement(\achar-class([arange(10,20), arange(30,40)])) == \achar-class([arange(1,9),arange(21,29),arange(41,1114111)]);
test bool testComp5() = complement(\achar-class([arange(10,35), arange(30,40)])) == \achar-class([arange(1,9),arange(41,1114111)]);

test bool testUnion1() = union(\char-class([range(10,20)]), \char-class([range(30, 40)])) == \char-class([range(10,20), range(30,40)]);
test bool testUnion2() = union(\char-class([range(10,25)]), \char-class([range(20, 40)])) == \char-class([range(10,40)]);
test bool testUnion1() = union(\achar-class([arange(10,20)]), \achar-class([arange(30, 40)])) == \achar-class([arange(10,20), arange(30,40)]);
test bool testUnion2() = union(\achar-class([arange(10,25)]), \achar-class([arange(20, 40)])) == \achar-class([arange(10,40)]);

test bool testInter1() = intersection(\char-class([range(10,20)]), \char-class([range(30, 40)])) == \char-class([]);
test bool testInter2() = intersection(\char-class([range(10,25)]), \char-class([range(20, 40)])) == \char-class([range(20, 25)]);
test bool testInter1() = intersection(\achar-class([arange(10,20)]), \achar-class([arange(30, 40)])) == \achar-class([]);
test bool testInter2() = intersection(\achar-class([arange(10,25)]), \achar-class([arange(20, 40)])) == \achar-class([arange(20, 25)]);

test bool testDiff1() = difference(\char-class([range(10,30)]), \char-class([range(20,25)])) == \char-class([range(10,19), range(26,30)]);
test bool testDiff2() = difference(\char-class([range(10,30), range(40,50)]), \char-class([range(25,45)])) ==\char-class( [range(10,24), range(46,50)]);
test bool testDiff1() = difference(\achar-class([arange(10,30)]), \achar-class([arange(20,25)])) == \achar-class([arange(10,19), arange(26,30)]);
test bool testDiff2() = difference(\achar-class([arange(10,30), arange(40,50)]), \achar-class([arange(25,45)])) ==\achar-class( [arange(10,24), arange(46,50)]);


Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,56 @@ import lang::rascalcore::check::AType;

public AGrammar GEMPTY = grammar({sort("S")}, ());

private AType \sort(str sname) = aadt(sname, [], contextFreeSyntax());

private AProduction pr(AType rhs, list[AType] lhs) {
return prod(rhs,lhs);
}

public AGrammar G0 = grammar({sort("S")}, (
sort("S"): choice(sort("S"), { pr(sort("S"), [ lit("0") ]) }),
lit("0"): choice(lit("0"), { pr(lit("0"),[\char-class([range(48,48)])]) })
sort("S"): choice(sort("S"), { pr(sort("S"), [ alit("0") ]) }),
alit("0"): choice(alit("0"), { pr(alit("0"),[\achar-class([arange(48,48)])]) })
));

public map[AType sort, AProduction def] Lit1 = (
lit("*"): choice(lit("*"), { pr(lit("*"),[\char-class([range(42,42)])]) }),
lit("+"): choice(lit("+"), { pr(lit("+"),[\char-class([range(43,43)])]) }),
lit("0"): choice(lit("0"), { pr(lit("0"),[\char-class([range(48,48)])]) }),
lit("1"): choice(lit("1"), { pr(lit("1"),[\char-class([range(49,49)])]) })
alit("*"): choice(alit("*"), { pr(alit("*"),[\achar-class([arange(42,42)])]) }),
alit("+"): choice(alit("+"), { pr(alit("+"),[\achar-class([arange(43,43)])]) }),
alit("0"): choice(alit("0"), { pr(alit("0"),[\achar-class([arange(48,48)])]) }),
alit("1"): choice(alit("1"), { pr(alit("1"),[\achar-class([arange(49,49)])]) })
);

public AGrammar GEXP = grammar({sort("E")}, (
sort("E"): choice(sort("E"), { pr(sort("E"), [sort("E"), lit("*"), sort("B")]),
pr(sort("E"), [sort("E"), lit("+"), sort("B")]),
sort("E"): choice(sort("E"), { pr(sort("E"), [sort("E"), alit("*"), sort("B")]),
pr(sort("E"), [sort("E"), alit("+"), sort("B")]),
pr(sort("E"), [sort("B")])
}),
sort("B"): choice(sort("B"), { pr(sort("B"), [lit("0")]),
pr(sort("B"), [lit("1")])
sort("B"): choice(sort("B"), { pr(sort("B"), [alit("0")]),
pr(sort("B"), [alit("1")])
})
) + Lit1);

public AGrammar GEXPPRIO = grammar( {sort("E")},
(
sort("E"): choice(sort("E"), { pr(sort("E"), [sort("T"), sort("E1")])}),
sort("E1"): choice(sort("E1"),{ pr(sort("E1"), [lit("+"), sort("T"), sort("E1")]),
sort("E1"): choice(sort("E1"),{ pr(sort("E1"), [alit("+"), sort("T"), sort("E1")]),
pr(sort("E1"), [])
}),


sort("T"): choice(sort("T"), { pr(sort("T"), [sort("F"), sort("T1")]) }),

sort("T1"): choice(sort("T1"),{ pr(sort("F"), [lit("*"), sort("F"), sort("T1")]),
sort("T1"): choice(sort("T1"),{ pr(sort("F"), [alit("*"), sort("F"), sort("T1")]),
pr(sort("T1"), []) }),

sort("F"): choice(sort("F"), { pr(sort("F"), [lit("("), sort("E"), lit(")")]),
pr(sort("F"), [lit("id")])
sort("F"): choice(sort("F"), { pr(sort("F"), [alit("("), sort("E"), alit(")")]),
pr(sort("F"), [alit("id")])
}),

lit("+"): choice(lit("+"), { pr(lit("+"),[\char-class([range(43,43)])]) }),
lit("*"): choice(lit("*"), { pr(lit("*"),[\char-class([range(42,42)])]) }),
alit("+"): choice(alit("+"), { pr(alit("+"),[\achar-class([arange(43,43)])]) }),
alit("*"): choice(alit("*"), { pr(alit("*"),[\achar-class([arange(42,42)])]) }),

lit("("): choice(lit("("), { pr(lit("("), [\char-class([range(40,40)])]) }),
lit(")"): choice(lit(")"), { pr(lit(")"), [\char-class([range(41,41)])]) }),
alit("("): choice(alit("("), { pr(alit("("), [\achar-class([arange(40,40)])]) }),
alit(")"): choice(alit(")"), { pr(alit(")"), [\achar-class([arange(41,41)])]) }),

lit("id"): choice(lit("id"), { pr(lit("id"), [\char-class([range(105,105)]),\char-class([range(100,100)])]) })
alit("id"): choice(alit("id"), { pr(alit("id"), [\achar-class([arange(105,105)]),\achar-class([arange(100,100)])]) })
));

0 comments on commit 1a13702

Please sign in to comment.