Merge pull request #13428 from s-hadinger/berry_python_compat2

Berry python compat for ranges
This commit is contained in:
s-hadinger 2021-10-20 23:24:57 +02:00 committed by GitHub
commit 8c8933f8f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -20,6 +20,7 @@
#include "be_decoder.h"
#include "be_debug.h"
#include "be_exec.h"
#include <limits.h>
#define OP_NOT_BINARY TokenNone
#define OP_NOT_UNARY TokenNone
@ -30,6 +31,17 @@
#define FUNC_METHOD 1
#define FUNC_ANONYMOUS 2
#if BE_INTGER_TYPE == 0 /* int */
#define M_IMAX INT_MAX
#define M_IMIN INT_MIN
#elif BE_INTGER_TYPE == 1 /* long */
#define M_IMAX LONG_MAX
#define M_IMIN LONG_MIN
#else /* int64_t (long long) */
#define M_IMAX LLONG_MAX
#define M_IMIN LLONG_MIN
#endif
/* get binary operator priority */
#define binary_op_prio(op) (binary_op_prio_tab[cast_int(op) - OptAdd])
@ -1074,7 +1086,11 @@ static void sub_expr(bparser *parser, bexpdesc *e, int prio)
be_code_prebinop(finfo, op, e); /* and or */
init_exp(&e2, ETVOID, 0);
sub_expr(parser, &e2, binary_op_prio(op)); /* parse right side */
check_var(parser, &e2); /* check if valid */
if ((e2.type == ETVOID) && (op == OptConnect)) {
init_exp(&e2, ETINT, M_IMAX);
} else {
check_var(parser, &e2); /* check if valid */
}
be_code_binop(finfo, op, e, &e2, -1); /* encode binary op */
op = get_binop(parser); /* is there a following binop? */
}

View File

@ -38,7 +38,7 @@ check(45.e+2, 4500)
test_source('x = 5; 0...x;', 'unexpected symbol near \'.\'')
test_source('x = 5; 0...x;', 'unexpected symbol near \'.\'')
test_source('45..', 'unexpected symbol near \'EOS\'')
# test_source('45..', 'unexpected symbol near \'EOS\'')
test_source('0xg', 'invalid hexadecimal number')
test_source('"\\x5g"', 'invalid hexadecimal number')
test_source('0x5g', 'malformed number')

View File

@ -34,3 +34,8 @@ assert(s.format("%i%%", 12) == "12%")
assert(s.format("%i%%%i", 12, 13) == "12%13")
assert(s.format("%s%%", "foo") == "foo%")
assert(s.format("%.1f%%", 3.5) == "3.5%")
s="azerty"
assert(s[1..2] == "ze")
assert(s[1..] == "zerty")
assert(s[1..-1] == "zerty")