Skip to content

Commit

Permalink
Make some interpreter / reader errors a bit nicer
Browse files Browse the repository at this point in the history
Previously, we produced errors like this:

    gap> function() 123; end;
    Syntax error: inside a function, statement or 'end' expected
    function() 123; end;
               ^^^

This now is slightly more helpful and reads as follows.

    gap> function() 123; end;
    Syntax error: while parsing a function: statement or 'end' expected
    function() 123; end;
               ^^^

Similar adjustments are made for loops, atomic blocks and if statements.
  • Loading branch information
fingolfin committed Mar 26, 2019
1 parent 1eb79a6 commit bf9bec2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ static void ReadFuncExpr (
ReadFuncExprBody(follow, 0, nloc, args, startLine);

/* 'end' */
Match( S_END, "end", follow );
Match(S_END, "while parsing a function: statement or 'end'", follow);
}


Expand Down Expand Up @@ -1994,7 +1994,7 @@ static void ReadIf (
}

/* 'fi' */
Match( S_FI, "fi", follow );
Match(S_FI, "while parsing an 'if' statement: statement or 'fi'", follow);
TRY_IF_NO_ERROR { IntrIfEnd( nrb ); }
}

Expand Down Expand Up @@ -2044,7 +2044,7 @@ static void ReadFor (
ReaderState()->LoopNesting--;

/* 'od' */
Match( S_OD, "od", follow );
Match(S_OD, "while parsing a 'for' loop: statement or 'od'", follow);
TRY_IF_NO_ERROR {
IntrForEnd();
}
Expand Down Expand Up @@ -2095,7 +2095,7 @@ static void ReadWhile (
ReaderState()->LoopNesting--;

/* 'od' */
Match( S_OD, "od", follow );
Match(S_OD, "while parsing a 'while' loop: statement or 'od'", follow);
TRY_IF_NO_ERROR {
IntrWhileEnd();
}
Expand Down Expand Up @@ -2171,7 +2171,7 @@ static void ReadAtomic (
TRY_IF_NO_ERROR { IntrAtomicEndBody( nrs ); }

/* 'od' */
Match( S_OD, "od", follow );
Match(S_OD, "while parsing an atomic block: statement or 'od'", follow);
TRY_IF_NO_ERROR {
IntrAtomicEnd();
}
Expand Down Expand Up @@ -2225,7 +2225,7 @@ static void ReadRepeat (
ReaderState()->LoopNesting--;

/* 'until' <Expr> */
Match( S_UNTIL, "until", EXPRBEGIN|follow );
Match(S_UNTIL, "while parsing a 'repeat' loop: statement or 'until'", EXPRBEGIN|follow);
ReadExpr( follow, 'r' );
TRY_IF_NO_ERROR {
IntrRepeatEnd();
Expand Down
3 changes: 2 additions & 1 deletion tst/testbugfix/2012-09-06-t00253.tst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gap> Read(s);
Syntax error: ) expected in stream:4
v := rec(a := [];);
^
Syntax error: end expected in stream:5
Syntax error: while parsing a function: statement or 'end' expected in stream:\
5
od;
^^
26 changes: 26 additions & 0 deletions tst/testinstall/error.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
gap> function() 123; end;
Syntax error: while parsing a function: statement or 'end' expected in stream:\
1
function() 123; end;
^^^
gap> if true then 123; fi;
Syntax error: while parsing an 'if' statement: statement or 'fi' expected in s\
tream:1
if true then 123; fi;
^^^
gap> while true do 123; od;
Syntax error: while parsing a 'while' loop: statement or 'od' expected in stre\
am:1
while true do 123; od;
^^^
gap> repeat 123; until true;
Syntax error: while parsing a 'repeat' loop: statement or 'until' expected in \
stream:1
repeat 123; until true;
^^^
gap> for i in [1..3] do 123; od;
Syntax error: while parsing a 'for' loop: statement or 'od' expected in stream\
:1
for i in [1..3] do 123; od;
^^^
9 changes: 6 additions & 3 deletions tst/testinstall/help.tst
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ gap> if true then ?what fi;
Syntax error: '?' cannot be used in this context in stream:1
if true then ?what fi;
^^^^^^^^^
Syntax error: fi expected in stream:2
Syntax error: while parsing an 'if' statement: statement or 'fi' expected in s\
tream:2


#
gap> if false then ?what fi;
Syntax error: '?' cannot be used in this context in stream:1
if false then ?what fi;
^^^^^^^^^
Syntax error: fi expected in stream:2
Syntax error: while parsing an 'if' statement: statement or 'fi' expected in s\
tream:2


#
Expand All @@ -22,7 +24,8 @@ gap> f := function()
Syntax error: '?' cannot be used in this context in stream:2
?help
^^^^^
Syntax error: end expected in stream:3
Syntax error: while parsing a function: statement or 'end' expected in stream:\
3


#
Expand Down

0 comments on commit bf9bec2

Please sign in to comment.