: 0 )
/*
- FOR_TESTING_DEMO: This is used to test if we generate incorrect code (currently is bad)
+ FOR_TESTING_DEMO: This is used to test if we generate incorrect code (currently it is ok)
"\x{3B7}\x{342}"
"\x{3B9}\x{308}\x{301}"
*/
/*** GENERATED CODE ***/
#define is_FOR_TESTING_DEMO_utf8_safe(s,e) \
-( ( ((e)-(s) > 5) && ( 0xCE == ((U8*)s)[0] ) ) ? ( ( 0xB7 == ((U8*)s)[1] ) ?\
- ( ( 0xCD == ((U8*)s)[2] ) ? \
- ( ( 0x82 == ((U8*)s)[3] ) ? 4 : 0 ) \
+( ((e)-(s) > 5) ? \
+ ( ( 0xCE == ((U8*)s)[0] ) ? \
+ ( ( 0xB7 == ((U8*)s)[1] ) ? \
+ ( ( ( 0xCD == ((U8*)s)[2] ) && ( 0x82 == ((U8*)s)[3] ) ) ? 4 : 0 )\
: ( 0xB9 == ((U8*)s)[1] ) ? \
( ( ( ( ( 0xCC == ((U8*)s)[2] ) && ( 0x88 == ((U8*)s)[3] ) ) && ( 0xCC == ((U8*)s)[4] ) ) && ( 0x81 == ((U8*)s)[5] ) ) ? 6 : 0 )\
: 0 ) \
sub __clean {
my ( $expr )= @_;
+
our $parens;
$parens= qr/ (?> \( (?> (?: (?> [^()]+ ) | (??{ $parens }) )* ) \) ) /x;
- #print "$parens\n$expr\n";
+ ## remove redundant parens
1 while $expr =~ s/ \( \s* ( $parens ) \s* \) /$1/gx;
- 1 while $expr =~ s/ \( \s* ($parens) \s* \? \s*
- \( \s* ($parens) \s* \? \s* ($parens|[^:]+?) \s* : \s* ($parens|[^)]+?) \s* \)
- \s* : \s* \4 \s* \)/( ( $1 && $2 ) ? $3 : 0 )/gx;
+
+
+ # repeatedly simplify conditions like
+ # ( (cond1) ? ( (cond2) ? X : Y ) : Y )
+ # into
+ # ( ( (cond1) && (cond2) ) ? X : Y )
+ #
+ 1 while $expr =~ s/
+ \( \s*
+ ($parens) \s*
+ \? \s*
+ \( \s* ($parens) \s*
+ \? \s* ($parens|[^()?:]+?) \s*
+ : \s* ($parens|[^()?:]+?) \s*
+ \) \s*
+ : \s* \4 \s*
+ \)
+ /( ( $1 && $2 ) ? $3 : $4 )/gx;
+
return $expr;
}
=> high :fast
\p{_Perl_Quotemeta}
-FOR_TESTING_DEMO: This is used to test if we generate incorrect code (currently is bad)
+FOR_TESTING_DEMO: This is used to test if we generate incorrect code (currently it is ok)
=> UTF8 :safe
"\x{3B7}\x{342}"
"\x{3B9}\x{308}\x{301}"