[Python-checkins] cpython: check after comments, too (#13832)
benjamin.peterson
python-checkins at python.org
Thu Jan 19 23:48:31 CET 2012
http://hg.python.org/cpython/rev/00c4efbf57c3
changeset: 74532:00c4efbf57c3
user: Benjamin Peterson <benjamin at python.org>
date: Thu Jan 19 17:46:13 2012 -0500
summary:
check after comments, too (#13832)
files:
Lib/test/test_compile.py | 2 ++
Parser/parsetok.c | 22 ++++++++++++++++------
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -470,6 +470,8 @@
self.assertInvalidSingle('a = 13\nb = 187')
self.assertInvalidSingle('del x\ndel y')
self.assertInvalidSingle('f()\ng()')
+ self.assertInvalidSingle('f()\n# blah\nblah()')
+ self.assertInvalidSingle('f()\nxy # blah\nblah()')
def test_main():
support.run_unittest(TestSpecifics)
diff --git a/Parser/parsetok.c b/Parser/parsetok.c
--- a/Parser/parsetok.c
+++ b/Parser/parsetok.c
@@ -234,13 +234,23 @@
char *cur = tok->cur;
char c = *tok->cur;
- while (c == ' ' || c == '\t' || c == '\n' || c == '\014')
- c = *++cur;
+ for (;;) {
+ while (c == ' ' || c == '\t' || c == '\n' || c == '\014')
+ c = *++cur;
- if (c && c != '#') {
- err_ret->error = E_BADSINGLE;
- PyNode_Free(n);
- n = NULL;
+ if (!c)
+ break;
+
+ if (c != '#') {
+ err_ret->error = E_BADSINGLE;
+ PyNode_Free(n);
+ n = NULL;
+ break;
+ }
+
+ /* Suck up comment. */
+ while (c && c != '\n')
+ c = *++cur;
}
}
#endif
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list