summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-04-27 17:02:07 (GMT)
committerGitHub <noreply@github.com>2020-04-27 17:02:07 (GMT)
commit2b74c835a7280840a853e3a9aaeb83758b13a458 (patch)
treea8f64047d5872571e12d6c256bbc54a9551f8bb6 /Tools
parent9adccc1384568f4d46e37f698cb3e3a4f6ca0252 (diff)
downloadcpython-2b74c835a7280840a853e3a9aaeb83758b13a458.zip
cpython-2b74c835a7280840a853e3a9aaeb83758b13a458.tar.gz
cpython-2b74c835a7280840a853e3a9aaeb83758b13a458.tar.bz2
bpo-40334: Support CO_FUTURE_BARRY_AS_BDFL in the new parser (GH-19721)
This commit also allows to pass flags to the new parser in all interfaces and fixes a bug in the parser generator that was causing to inline rules with actions, making them disappear.
Diffstat (limited to 'Tools')
-rw-r--r--Tools/peg_generator/peg_extension/peg_extension.c7
-rw-r--r--Tools/peg_generator/pegen/c_generator.py10
2 files changed, 13 insertions, 4 deletions
diff --git a/Tools/peg_generator/peg_extension/peg_extension.c b/Tools/peg_generator/peg_extension/peg_extension.c
index d8d36a0..fb552ee 100644
--- a/Tools/peg_generator/peg_extension/peg_extension.c
+++ b/Tools/peg_generator/peg_extension/peg_extension.c
@@ -12,7 +12,6 @@ _build_return_object(mod_ty module, int mode, PyObject *filename_ob, PyArena *ar
} else {
result = Py_None;
Py_INCREF(result);
-
}
return result;
@@ -43,7 +42,8 @@ parse_file(PyObject *self, PyObject *args, PyObject *kwds)
goto error;
}
- mod_ty res = _PyPegen_run_parser_from_file(filename, Py_file_input, filename_ob, arena);
+ PyCompilerFlags flags = _PyCompilerFlags_INIT;
+ mod_ty res = _PyPegen_run_parser_from_file(filename, Py_file_input, filename_ob, &flags, arena);
if (res == NULL) {
goto error;
}
@@ -81,8 +81,9 @@ parse_string(PyObject *self, PyObject *args, PyObject *kwds)
goto error;
}
+ PyCompilerFlags flags = _PyCompilerFlags_INIT;
mod_ty res = _PyPegen_run_parser_from_string(the_string, Py_file_input, filename_ob,
- PyCF_IGNORE_COOKIE, arena);
+ &flags, arena);
if (res == NULL) {
goto error;
}
diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py
index 5b9d804..6c4b8f1 100644
--- a/Tools/peg_generator/pegen/c_generator.py
+++ b/Tools/peg_generator/pegen/c_generator.py
@@ -73,9 +73,17 @@ class CCallMakerVisitor(GrammarVisitor):
return "literal", f"_PyPegen_expect_token(p, {type})"
def visit_Rhs(self, node: Rhs) -> Tuple[Optional[str], str]:
+ def can_we_inline(node):
+ if len(node.alts) != 1 or len(node.alts[0].items) != 1:
+ return False
+ # If the alternative has an action we cannot inline
+ if getattr(node.alts[0], "action", None) is not None:
+ return False
+ return True
+
if node in self.cache:
return self.cache[node]
- if len(node.alts) == 1 and len(node.alts[0].items) == 1:
+ if can_we_inline(node):
self.cache[node] = self.visit(node.alts[0].items[0])
else:
name = self.gen.name_node(node)