[3.10] bpo-45408: Don't override previous tokenizer errors in the second parser pass (GH-28812). (GH-28813)

(cherry picked from commit 0219017df7ec41839fd0d56a3076b5f09c58d313)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
diff --git a/Parser/pegen.c b/Parser/pegen.c
index e20e926..1bb975d 100644
--- a/Parser/pegen.c
+++ b/Parser/pegen.c
@@ -1321,13 +1321,16 @@
 {
     void *res = _PyPegen_parse(p);
     if (res == NULL) {
+        if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_SyntaxError)) {
+            return NULL;
+        }
         Token *last_token = p->tokens[p->fill - 1];
         reset_parser_state(p);
         _PyPegen_parse(p);
         if (PyErr_Occurred()) {
             // Prioritize tokenizer errors to custom syntax errors raised
             // on the second phase only if the errors come from the parser.
-            if (p->tok->done != E_ERROR && PyErr_ExceptionMatches(PyExc_SyntaxError)) {
+            if (p->tok->done == E_DONE && PyErr_ExceptionMatches(PyExc_SyntaxError)) {
                 _PyPegen_check_tokenizer_errors(p);
             }
             return NULL;