From 1c7a857ecbbc616a3e48dcbda717cc3072f554c0 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 6 May 2018 21:33:56 +0200 Subject: [PATCH] kernel: flush input line after early syntax error Fixes a mild regression introduce by PR #1015, which in turn attempted to fix parts of issue #995. With GAP 4.8 and also with this fix: gap> 1.2\3; Syntax error: Badly formed number 1.2\3; ^ In GAP 4.9: gap> 1.2\3; Syntax error: Badly formed number 1.2\3; ^ 3 --- src/read.c | 3 +- tst/testinstall/kernel/read.tst | 66 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/read.c b/src/read.c index dc237a8a35..c31f0dab4d 100644 --- a/src/read.c +++ b/src/read.c @@ -2713,8 +2713,9 @@ ExecStatus ReadEvalCommand(Obj context, Obj *evalResult, UInt *dualSemicolon) /* get the first symbol from the input */ Match( STATE(Symbol), "", 0UL ); - /* using TRY_READ sets the jump buffer and mucks up the interpreter */ + // if scanning the first symbol produced a syntax error, abort if (STATE(NrError)) { + FlushRestOfInputLine(); return STATUS_ERROR; } diff --git a/tst/testinstall/kernel/read.tst b/tst/testinstall/kernel/read.tst index 98a1c4b642..63a18482b8 100644 --- a/tst/testinstall/kernel/read.tst +++ b/tst/testinstall/kernel/read.tst @@ -64,5 +64,71 @@ Syntax error: Identifier expected in stream:1 rec("a":=1); ^ +# +# ReadEvalCommand +# +# See also https://github.com/gap-system/gap/issues/995 +# + +# some inputs which immediately trigger an error in ReadEvalCommand, +# even before an interpreter has been started +gap> ' +Syntax error: Character literal must not include in stream:1 +' +^ +gap> 'x +Syntax error: Missing single quote in character constant in stream:1 +'x + ^ +gap> " +Syntax error: String must not include in stream:1 +" +^ +gap> "x +Syntax error: String must not include in stream:1 +"x + ^ + +# similar inputs to the above, but here the error is triggered a bit +# later, after the interpreter has already started +gap> s := ' +Syntax error: Character literal must not include in stream:1 +s := ' + ^ +Syntax error: ; expected in stream:2 +^ +gap> s := 'x +Syntax error: Missing single quote in character constant in stream:1 +s := 'x + ^ +Syntax error: ; expected in stream:2 +^ +gap> s := " +Syntax error: String must not include in stream:1 +s := " + ^ +Syntax error: ; expected in stream:2 +^ +gap> s := "x +Syntax error: String must not include in stream:1 +s := "x + ^ +Syntax error: ; expected in stream:2 +^ + +# errors in the middle of parsing a float literal +gap> 12.34\56; +Syntax error: Badly formed number in stream:1 +12.34\56; + ^ +gap> 12.34\a56; +Syntax error: Badly formed number in stream:1 +12.34\a56; + ^ +gap> 12.34\56a; +Syntax error: Badly formed number in stream:1 +12.34\56a; + ^ + # gap> STOP_TEST("kernel/read.tst", 1);