From 13e8287554039e9fbea64dfe943e3d4eef633b50 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Wed, 20 Oct 2021 22:59:16 +0200 Subject: [PATCH] Berry python compat for ranges --- lib/libesp32/Berry/src/be_parser.c | 6 +++++- lib/libesp32/Berry/tests/lexer.be | 2 +- lib/libesp32/Berry/tests/string.be | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/libesp32/Berry/src/be_parser.c b/lib/libesp32/Berry/src/be_parser.c index fc7c06de5..d98988d9f 100644 --- a/lib/libesp32/Berry/src/be_parser.c +++ b/lib/libesp32/Berry/src/be_parser.c @@ -1074,7 +1074,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, -1); + } 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? */ } diff --git a/lib/libesp32/Berry/tests/lexer.be b/lib/libesp32/Berry/tests/lexer.be index 3dc34169d..abdb4d903 100644 --- a/lib/libesp32/Berry/tests/lexer.be +++ b/lib/libesp32/Berry/tests/lexer.be @@ -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') diff --git a/lib/libesp32/Berry/tests/string.be b/lib/libesp32/Berry/tests/string.be index 683f7d585..479af1cb4 100644 --- a/lib/libesp32/Berry/tests/string.be +++ b/lib/libesp32/Berry/tests/string.be @@ -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")