Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change SyntaxError to underline complete last token #2574

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hpcgap/tst/testinstall/atomic_basic.tst
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ end
gap> h5 := function(readwrite x, readonly y, z) end;;
Syntax error: 'readwrite' argument of non-atomic function in stream:1
h5 := function(readwrite x, readonly y, z) end;;
^
^^^^^^^^^
gap> h5 := function(readonly x, readonly y, z) end;;
Syntax error: 'readonly' argument of non-atomic function in stream:1
h5 := function(readonly x, readonly y, z) end;;
^
^^^^^^^^
gap> STOP_TEST("atomic_basic.tst", 1);
2 changes: 2 additions & 0 deletions src/gapstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ typedef struct GAPState {
UInt NrError;
UInt NrErrLine;
UInt Symbol;
UInt SymbolStartPos;
UInt SymbolStartLine;

const Char * Prompt;

Expand Down
27 changes: 21 additions & 6 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,23 @@ static void SyntaxErrorOrWarning(const Char * msg, UInt error)
Pr("%s", (Int)line, 0);

// print a '^' pointing to the current position
Int startPos = STATE(SymbolStartPos);
Int pos = GetInputLinePosition();
for (Int i = 0; i < pos; i++) {
if (line[i] == '\t')
Pr("\t", 0, 0);
else
Pr(" ", 0, 0);
if (STATE(SymbolStartLine) != GetInputLineNumber())
startPos = 0;
if (startPos <= pos) {
Int i;
for (i = 0; i <= startPos; i++) {
if (line[i] == '\t')
Pr("\t", 0, 0);
else
Pr(" ", 0, 0);
}

for (; i <= pos; i++)
Pr("^", 0, 0);
Pr("\n", 0, 0);
}
Pr("^\n", 0, 0);

// close error output
CloseOutput();
Expand Down Expand Up @@ -883,6 +892,9 @@ static void GetHelp(void)
*/
static UInt NextSymbol(void)
{
STATE(SymbolStartLine) = GetInputLineNumber();
STATE(SymbolStartPos) = GetInputLinePosition();

Char c = PEEK_CURR_CHAR();

// if no character is available then get one
Expand All @@ -898,6 +910,9 @@ static UInt NextSymbol(void)
c = GET_NEXT_CHAR();
}

STATE(SymbolStartLine) = GetInputLineNumber();
STATE(SymbolStartPos) = GetInputLinePosition();

// switch according to the character
if (IsAlpha(c)) {
return GetIdent(0);
Expand Down
2 changes: 1 addition & 1 deletion tst/test-error/debug-var.g.out
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ brk> Unbind(x);
brk> x:=42;
Syntax warning: Unbound global variable in *errin*:4
x:=42;
^
^^
42
brk> IsBound(x);
true
Expand Down
3 changes: 0 additions & 3 deletions tst/test32bit/randlist.tst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,3 @@ gap> List([1..10], i-> Random(rs, 1,10^(3*i)));
52224684171237700022, 63091858766485771208964, 391269615753496331510430301,
929557928485066381724613674190 ]
gap> STOP_TEST( "randlist.tst", 1);
#############################################################################
##
#E
3 changes: 0 additions & 3 deletions tst/test64bit/randlist.tst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,3 @@ gap> List([1..10], i-> Random(rs, 1,10^(3*i)));
234476903267325497175, 596997600529202583174722,
290628328961307271818818898, 17261260615457929009978390979 ]
gap> STOP_TEST( "randlist.tst", 1);
#############################################################################
##
#E
2 changes: 1 addition & 1 deletion tst/testbugfix/2012-09-06-t00253.tst
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Syntax error: ) expected in stream:4
^
Syntax error: end expected in stream:5
od;
^
^^
2 changes: 1 addition & 1 deletion tst/testbugfix/2013-08-21-t00295.tst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ int in stream:1
. . . .
^
Syntax error: Record component name expected in stream:2
^

1 change: 0 additions & 1 deletion tst/testinstall/IsLIBGAP.tst
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ gap> START_TEST("IsLIBGAP.tst");
gap> IsBound( IsLIBGAP );
true
gap> STOP_TEST( "IsLIBGAP.tst", 1);

18 changes: 9 additions & 9 deletions tst/testinstall/atomic_basic.tst
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,37 @@ end
gap> h5 := function(readwrite x, readonly y, z) end;;
Syntax error: 'readwrite' argument of non-atomic function in stream:1
h5 := function(readwrite x, readonly y, z) end;;
^
^^^^^^^^^
gap> h5 := function(readonly x, readonly y, z) end;;
Syntax error: 'readonly' argument of non-atomic function in stream:1
h5 := function(readonly x, readonly y, z) end;;
^
^^^^^^^^
gap> h5 := {readonly x} -> x;
Syntax error: 'readonly' argument of non-atomic function in stream:1
h5 := {readonly x} -> x;
^
^^^^^^^^
gap> h5 := {readonly x} -> x;
Syntax error: 'readonly' argument of non-atomic function in stream:1
h5 := {readonly x} -> x;
^
^^^^^^^^
gap> h5 := {x, readonly y} -> x;
Syntax error: 'readonly' argument of non-atomic function in stream:1
h5 := {x, readonly y} -> x;
^
^^^^^^^^
gap> h5 := {readwrite x, y} -> x;
Syntax error: 'readwrite' argument of non-atomic function in stream:1
h5 := {readwrite x, y} -> x;
^
^^^^^^^^^
gap> h5 := {x, readwrite y} -> x;
Syntax error: 'readwrite' argument of non-atomic function in stream:1
h5 := {x, readwrite y} -> x;
^
^^^^^^^^^
gap> h5 := {readwrite} -> x;
Syntax error: 'readwrite' argument of non-atomic function in stream:1
h5 := {readwrite} -> x;
^
^^^^^^^^^
gap> h5 := {readwrite readonly x} -> x;
Syntax error: 'readwrite' argument of non-atomic function in stream:1
h5 := {readwrite readonly x} -> x;
^
^^^^^^^^^
gap> STOP_TEST("atomic_basic.tst", 1);
36 changes: 18 additions & 18 deletions tst/testinstall/break.tst
Original file line number Diff line number Diff line change
Expand Up @@ -4,82 +4,82 @@ gap> START_TEST("break.tst");
gap> break;
Syntax error: 'break' statement not enclosed in a loop in stream:1
break;
^
^^^^^
gap> if true then break; fi;
Syntax error: 'break' statement not enclosed in a loop in stream:1
if true then break; fi;
^
^^^^^
gap> if false then break; fi;
Syntax error: 'break' statement not enclosed in a loop in stream:1
if false then break; fi;
^
^^^^^
gap> f := function() break; end;
Syntax error: 'break' statement not enclosed in a loop in stream:1
f := function() break; end;
^
^^^^^
gap> for i in [1..5] do List([1..5], function(x) break; return 1; end); od;
Syntax error: 'break' statement not enclosed in a loop in stream:1
for i in [1..5] do List([1..5], function(x) break; return 1; end); od;
^
^^^^^

#
gap> continue;
Syntax error: 'continue' statement not enclosed in a loop in stream:1
continue;
^
^^^^^^^^
gap> if true then continue; fi;
Syntax error: 'continue' statement not enclosed in a loop in stream:1
if true then continue; fi;
^
^^^^^^^^
gap> if false then continue; fi;
Syntax error: 'continue' statement not enclosed in a loop in stream:1
if false then continue; fi;
^
^^^^^^^^
gap> f := function() continue; end;
Syntax error: 'continue' statement not enclosed in a loop in stream:1
f := function() continue; end;
^
^^^^^^^^
gap> for i in [1..5] do List([1..5], function(x) continue; return 1; end); od;
Syntax error: 'continue' statement not enclosed in a loop in stream:1
for i in [1..5] do List([1..5], function(x) continue; return 1; end); od;
^
^^^^^^^^

#
#
gap> if true then quit; fi;
Syntax error: 'quit;' cannot be used in this context in stream:1
if true then quit; fi;
^
^^^^
gap> if false then quit; fi;
Syntax error: 'quit;' cannot be used in this context in stream:1
if false then quit; fi;
^
^^^^
gap> f := function() quit; end;
Syntax error: 'quit;' cannot be used in this context in stream:1
f := function() quit; end;
^
^^^^
gap> for i in [1..5] do quit; od;
Syntax error: 'quit;' cannot be used in this context in stream:1
for i in [1..5] do quit; od;
^
^^^^

#
gap> if true then QUIT; fi;
Syntax error: 'QUIT;' cannot be used in this context in stream:1
if true then QUIT; fi;
^
^^^^
gap> if false then QUIT; fi;
Syntax error: 'QUIT;' cannot be used in this context in stream:1
if false then QUIT; fi;
^
^^^^
gap> f := function() QUIT; end;
Syntax error: 'QUIT;' cannot be used in this context in stream:1
f := function() QUIT; end;
^
^^^^
gap> for i in [1..5] do QUIT; od;
Syntax error: 'QUIT;' cannot be used in this context in stream:1
for i in [1..5] do QUIT; od;
^
^^^^

#
gap> f := function() local i; for i in [1..5] do continue; od; end;;
Expand Down
4 changes: 2 additions & 2 deletions tst/testinstall/float.tst
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ gap> 1.1_;
gap> 1.x1;
Syntax error: Badly formed number in stream:1
1.x1;
^
^^^
gap> 1.1xx;
Syntax error: Badly formed number in stream:1
1.1xx;
^
^^^^

# The following is potentially correct, *if* there is a conversion handler for
# 'x' installed, which normally isn't the case.
Expand Down
2 changes: 1 addition & 1 deletion tst/testinstall/function.tst
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ gap> f(2,3);
gap> f := ({x,y..} -> [x,y]);
Syntax error: Three dots required for variadic argument list in stream:1
f := ({x,y..} -> [x,y]);
^
^^
gap> f := ({x,y...} -> [x,y]);
function( x, y... ) ... end
gap> f(2,3);
Expand Down
12 changes: 6 additions & 6 deletions tst/testinstall/help.tst
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
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
^


#
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
^


#
gap> f := function()
> ?help
Syntax error: '?' cannot be used in this context in stream:2
?help
^
^^^^^
Syntax error: end expected in stream:3
^

2 changes: 1 addition & 1 deletion tst/testinstall/interpreter.tst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Error, <expr> must be 'true' or 'false' (not a integer)
gap> function() quit; end;
Syntax error: 'quit;' cannot be used in this context in stream:1
function() quit; end;
^
^^^^

#
# return is not allowed in interpreter
Expand Down
Loading