imaginary_number[expr_ty]:
| imag=NUMBER { _PyPegen_ensure_imaginary(p, imag) }
- | '+' imag=NUMBER { _PyPegen_ensure_imaginary(p, imag) }
capture_pattern[pattern_ty]:
| target=pattern_capture_target { _PyAST_MatchAs(NULL, target->v.Name.id, EXTRA) }
self.assertEqual(y, 0)
def test_patma_265(self):
- x = 0.25 - 1.75j
- match x:
- case 0.25 - +1.75j:
- y = 0
- self.assertEqual(x, 0.25 - 1.75j)
- self.assertEqual(y, 0)
-
- def test_patma_266(self):
x = 0
match x:
case +1e1000:
pass
""")
+ def test_duplicate_sign_in_complex_1(self):
+ self.assert_syntax_error("""
+ match ...:
+ case 0 ++ 0j:
+ pass
+ """)
+
+ def test_duplicate_sign_in_complex_2(self):
+ self.assert_syntax_error("""
+ match ...:
+ case 0 -+ 0j:
+ pass
+ """)
+
+ def test_duplicate_sign_in_complex_3(self):
+ self.assert_syntax_error("""
+ match ...:
+ case 0 +- 0j:
+ pass
+ """)
+
+ def test_duplicate_sign_in_complex_4(self):
+ self.assert_syntax_error("""
+ match ...:
+ case 0 -- 0j:
+ pass
+ """)
+
class TestTypeErrors(unittest.TestCase):
def test_accepts_positional_subpatterns_0(self):
return _res;
}
-// imaginary_number: NUMBER | '+' NUMBER
+// imaginary_number: NUMBER
static expr_ty
imaginary_number_rule(Parser *p)
{
D(fprintf(stderr, "%*c%s imaginary_number[%d-%d]: %s failed!\n", p->level, ' ',
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NUMBER"));
}
- { // '+' NUMBER
- if (p->error_indicator) {
- p->level--;
- return NULL;
- }
- D(fprintf(stderr, "%*c> imaginary_number[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "'+' NUMBER"));
- Token * _literal;
- expr_ty imag;
- if (
- (_literal = _PyPegen_expect_token(p, 14)) // token='+'
- &&
- (imag = _PyPegen_number_token(p)) // NUMBER
- )
- {
- D(fprintf(stderr, "%*c+ imaginary_number[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'+' NUMBER"));
- _res = _PyPegen_ensure_imaginary ( p , imag );
- if ((_res == NULL || p->error_indicator) && PyErr_Occurred()) {
- p->error_indicator = 1;
- p->level--;
- return NULL;
- }
- goto done;
- }
- p->mark = _mark;
- D(fprintf(stderr, "%*c%s imaginary_number[%d-%d]: %s failed!\n", p->level, ' ',
- p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "'+' NUMBER"));
- }
_res = NULL;
done:
p->level--;