Author: Matti Picus <matti.pi...@gmail.com>
Date: 2018-04-10 11:59 +0300
diff --git a/blog/draft/2018-04-better-syntaxerrors.rst
@@ -1,26 +1,25 @@
Improving SyntaxError in PyPy
-Since about a year, my halftime job at the uni has been to teach non-CS
+For the last year, my halftime job has been to teach non-CS uni students
to program in Python. While doing that, I have been trying to see what common
-stumbling blocks are, for programmers that are just starting out. There are
-things that could be said here, but one theme that emerges are
+stumbling blocks exist for novice programmers. There are many
+things that could be said here, but a common theme that emerges is
hard-to-understand error messages. One source of such error messages,
-particularly when starting out, are ``SyntaxErrors``.
+particularly when starting out, is ``SyntaxErrors``.
PyPy's parser (mostly following the architecture of CPython) uses a
regular-expression-based tokenizer with some cleverness to deal with
indentation, and a simple LR(1) parser. Both of these components obviously
-produce errors for invalid syntax, but the messages are not that great. Often,
+produce errors for invalid syntax, but the messages are not very helpful.
the message is just "invalid syntax", without any hint of what exactly is
-In the last couple of weeks I have invested a little bit of effor to make them
+In the last couple of weeks I have invested a little bit of effort to make
tiny bit better. Here are some examples.
-The first class of errors is when a token is missing, but there is only one
+The first class of errors occurs when a token is missing, often there is only
valid token that the parser expects. This happens most commonly by leaving out
the ':' after control flow statements (which is the syntax error I personally
still make at least a few times a day). In such situations, the parser will now
@@ -65,10 +64,10 @@
-Another source of errors are unmatched parenthesis. Here, PyPy has always had
+Another source of errors are unmatched parentheses. Here, PyPy has always had
slightly better error messages than CPython:
.. sourcecode:: pycon
@@ -89,7 +88,7 @@
SyntaxError: unmatched ')'
-The same is true for parenthesis that are never closed (the call to ``eval`` is
+The same is true for parentheses that are never closed (the call to ``eval`` is
needed to get the error, otherwise the repl will just wait for more input):
.. sourcecode:: pycon
@@ -141,12 +140,12 @@
Obviously these are just some very simple cases, and there is still a lot of
room for improvement (one huge problem is that only a simple ``SyntaxError`` is
ever shown per parse attempt, but fixing that is rather hard).
If you have a favorite unhelpful SyntaxError message you love to hate, please
-tell us in the comments and we might try to improve it. Other kinds of bad
-messages are also always welcome!
+tell us in the comments and we might try to improve it. Other kinds of
+non-informative error messages are also always welcome!
pypy-commit mailing list