Skip to content

Commit

Permalink
kernel: flush input line after early syntax error
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fingolfin committed May 11, 2018
1 parent ae9ae13 commit 1c7a857
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
66 changes: 66 additions & 0 deletions tst/testinstall/kernel/read.tst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <newline> in stream:1
'
^
gap> 'x
Syntax error: Missing single quote in character constant in stream:1
'x
^
gap> "
Syntax error: String must not include <newline> in stream:1
"
^
gap> "x
Syntax error: String must not include <newline> 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 <newline> 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 <newline> in stream:1
s := "
^
Syntax error: ; expected in stream:2
^
gap> s := "x
Syntax error: String must not include <newline> 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);

0 comments on commit 1c7a857

Please sign in to comment.