@@ -2,7 +2,10 @@ extern crate peg;
22
33peg:: parser!( grammar arithmetic( ) for str {
44 pub ( crate ) rule no_assoc( ) = precedence! {
5- @ "+" @ { }
5+ ( @) "||" @ { }
6+ --
7+ @ "<" @ { }
8+ @ ">" @ { }
69 --
710 @ "?" { }
811 --
@@ -14,26 +17,33 @@ peg::parser!(grammar arithmetic() for str {
1417
1518#[ test]
1619fn main ( ) {
17- assert ! ( arithmetic:: no_assoc( "x+x" ) . is_ok( ) ) ;
20+ assert ! ( arithmetic:: no_assoc( "x<x" ) . is_ok( ) ) ;
21+ assert ! ( arithmetic:: no_assoc( "x>x" ) . is_ok( ) ) ;
1822 assert ! ( arithmetic:: no_assoc( "-x" ) . is_ok( ) ) ;
1923 assert ! ( arithmetic:: no_assoc( "x?" ) . is_ok( ) ) ;
2024
25+ assert ! ( arithmetic:: no_assoc( "x||x" ) . is_ok( ) ) ;
26+ assert ! ( arithmetic:: no_assoc( "x<x||x" ) . is_ok( ) ) ;
27+ assert ! ( arithmetic:: no_assoc( "x||x<x" ) . is_ok( ) ) ;
28+ assert ! ( arithmetic:: no_assoc( "x<x||x<x" ) . is_ok( ) ) ;
29+
2130 assert ! ( arithmetic:: no_assoc( "-x?" ) . is_ok( ) ) ;
22- assert ! ( arithmetic:: no_assoc( "x+ -x" ) . is_ok( ) ) ;
23- assert ! ( arithmetic:: no_assoc( "-x+ x" ) . is_ok( ) ) ;
24- assert ! ( arithmetic:: no_assoc( "-x+ -x" ) . is_ok( ) ) ;
25- assert ! ( arithmetic:: no_assoc( "x+ x?" ) . is_ok( ) ) ;
26- assert ! ( arithmetic:: no_assoc( "x?+ x" ) . is_ok( ) ) ;
27- assert ! ( arithmetic:: no_assoc( "x?+ x?" ) . is_ok( ) ) ;
28- assert ! ( arithmetic:: no_assoc( "x+ -x?" ) . is_ok( ) ) ;
29- assert ! ( arithmetic:: no_assoc( "x?+ -x?" ) . is_ok( ) ) ;
30- assert ! ( arithmetic:: no_assoc( "-x?+ -x?" ) . is_ok( ) ) ;
31+ assert ! ( arithmetic:: no_assoc( "x< -x" ) . is_ok( ) ) ;
32+ assert ! ( arithmetic:: no_assoc( "-x< x" ) . is_ok( ) ) ;
33+ assert ! ( arithmetic:: no_assoc( "-x< -x" ) . is_ok( ) ) ;
34+ assert ! ( arithmetic:: no_assoc( "x< x?" ) . is_ok( ) ) ;
35+ assert ! ( arithmetic:: no_assoc( "x?< x" ) . is_ok( ) ) ;
36+ assert ! ( arithmetic:: no_assoc( "x?< x?" ) . is_ok( ) ) ;
37+ assert ! ( arithmetic:: no_assoc( "x< -x?" ) . is_ok( ) ) ;
38+ assert ! ( arithmetic:: no_assoc( "x?< -x?" ) . is_ok( ) ) ;
39+ assert ! ( arithmetic:: no_assoc( "-x?< -x?" ) . is_ok( ) ) ;
3140
32- assert ! ( arithmetic:: no_assoc( "x+x+x" ) . is_err( ) ) ;
33- assert ! ( arithmetic:: no_assoc( "x?+x+x" ) . is_err( ) ) ;
34- assert ! ( arithmetic:: no_assoc( "-x+x+x" ) . is_err( ) ) ;
35- assert ! ( arithmetic:: no_assoc( "x+-x+x" ) . is_err( ) ) ;
36- assert ! ( arithmetic:: no_assoc( "x+x?+x" ) . is_err( ) ) ;
37- assert ! ( arithmetic:: no_assoc( "x+x?+-x" ) . is_err( ) ) ;
38- assert ! ( arithmetic:: no_assoc( "x+x?+x?" ) . is_err( ) ) ;
41+ assert ! ( arithmetic:: no_assoc( "x<x<x" ) . is_err( ) ) ;
42+ assert ! ( arithmetic:: no_assoc( "x<x>x" ) . is_err( ) ) ;
43+ assert ! ( arithmetic:: no_assoc( "x?<x<x" ) . is_err( ) ) ;
44+ assert ! ( arithmetic:: no_assoc( "-x<x<x" ) . is_err( ) ) ;
45+ assert ! ( arithmetic:: no_assoc( "x<-x<x" ) . is_err( ) ) ;
46+ assert ! ( arithmetic:: no_assoc( "x<x?<x" ) . is_err( ) ) ;
47+ assert ! ( arithmetic:: no_assoc( "x<x?<-x" ) . is_err( ) ) ;
48+ assert ! ( arithmetic:: no_assoc( "x<x?<x?" ) . is_err( ) ) ;
3949}
0 commit comments