make syntax error standard.

This commit is contained in:
Vítor Santos Costa 2012-05-03 00:16:11 +01:00
parent c3e3b0b50f
commit e1f6187395
4 changed files with 13 additions and 16 deletions

View File

@ -1431,9 +1431,11 @@ Yap_Error(yap_error_number type, Term where, char *format,...)
case SYNTAX_ERROR: case SYNTAX_ERROR:
{ {
int i; int i;
Term ti[1];
i = strlen(tmpbuf); i = strlen(tmpbuf);
nt[0] = where; ti[0] = MkAtomTerm(AtomSyntaxError);
nt[0] = Yap_MkApplTerm(FunctorShortSyntaxError, 1, ti);
psize -= i; psize -= i;
fun = FunctorError; fun = FunctorError;
serious = TRUE; serious = TRUE;
@ -1807,6 +1809,9 @@ E);
LOCAL_Error_Size = 0L; LOCAL_Error_Size = 0L;
} }
nt[1] = MkPairTerm(MkAtomTerm(Yap_LookupAtom(tmpbuf)), stack_dump); nt[1] = MkPairTerm(MkAtomTerm(Yap_LookupAtom(tmpbuf)), stack_dump);
if (type == SYNTAX_ERROR) {
nt[1] = MkPairTerm(where, nt[1]);
}
} }
} }
if (serious) { if (serious) {

View File

@ -383,8 +383,9 @@ GenerateSyntaxError(Term *tp, TokEntry *tokstart, IOSTREAM *sno USES_REGS)
if (tp) { if (tp) {
Term et[2]; Term et[2];
Term t = MkVarTerm(); Term t = MkVarTerm();
et[0] = syntax_error(tokstart, sno, &t); et[1] = MkPairTerm(syntax_error(tokstart, sno, &t), TermNil);
et[1] = MkAtomTerm(Yap_LookupAtom("Syntax error")); t = MkAtomTerm(AtomSyntaxError);
et[0] = Yap_MkApplTerm(FunctorShortSyntaxError,1,&t);
*tp = Yap_MkApplTerm(FunctorError, 2, et); *tp = Yap_MkApplTerm(FunctorError, 2, et);
} }
} }

View File

@ -255,8 +255,6 @@ print_message(Severity, Term) :-
'$print_system_message'(Term, Severity, Lines) '$print_system_message'(Term, Severity, Lines)
), !. ), !.
print_message(silent, _) :- !. print_message(silent, _) :- !.
print_message(_, error(syntax_error(syntax_error(_,between(_,L,_),_,_,_,_,StreamName)),_)) :- !,
format(user_error,'SYNTAX ERROR at ~a, close to ~d~n',[StreamName,L]).
print_message(_, loading(A, F)) :- !, print_message(_, loading(A, F)) :- !,
format(user_error,' % ~a ~a~n',[A,F]). format(user_error,' % ~a ~a~n',[A,F]).
print_message(_, loaded(A, F, _, Time, Space)) :- !, print_message(_, loaded(A, F, _, Time, Space)) :- !,
@ -284,13 +282,6 @@ print_message(_, Term) :-
current_prolog_flag(verbose, silent), !. current_prolog_flag(verbose, silent), !.
'$print_system_message'(_, banner, _) :- '$print_system_message'(_, banner, _) :-
current_prolog_flag(verbose, silent), !. current_prolog_flag(verbose, silent), !.
'$print_system_message'(Term, Level, Lines) :-
Term = error(syntax_error(syntax_error(_,_,_,_,_,_,_)),_), !,
flush_output(user_output),
flush_output(user_error),
'$messages':prefix(Level, LinePrefix, Stream, _, Lines), !,
% make sure we don't give a PC.
print_message_lines(Stream, LinePrefix, Lines).
'$print_system_message'(Term, Level, Lines) :- '$print_system_message'(Term, Level, Lines) :-
'$messages':prefix(Level, LinePrefix, Stream, Prefix), '$messages':prefix(Level, LinePrefix, Stream, Prefix),
'$messages':file_location(Prefix, LinesF, Lines), !, '$messages':file_location(Prefix, LinesF, Lines), !,

View File

@ -283,14 +283,14 @@ system_message(error(resource_error(trail), Where)) -->
[ 'RESOURCE ERROR- not enough trail space' - [Where] ]. [ 'RESOURCE ERROR- not enough trail space' - [Where] ].
system_message(error(signal(SIG,_), _)) --> system_message(error(signal(SIG,_), _)) -->
[ 'UNEXPECTED SIGNAL: ~a' - [SIG] ]. [ 'UNEXPECTED SIGNAL: ~a' - [SIG] ].
system_message(error(syntax_error(G,_,Msg,[],_,0,File), _)) --> system_message(error(syntax_error(_), [syntax_error(G,_,Msg,[],_,0,File)|_])) -->
[ 'SYNTAX ERROR at "~a", goal ~q: ~a' - [File,G,Msg] ]. [ 'SYNTAX ERROR at "~a", goal ~q: ~a' - [File,G,Msg] ].
% SWI like I/O error message. % SWI like I/O error message.
system_message(error(syntax_error(end_of_clause), stream(Stream, Line, _, _))) --> system_message(error(syntax_error(end_of_clause), [stream(Stream, Line, _, _)|_])) -->
[ 'SYNTAX ERROR ~a, stream ~w, near line ~d.' - ['Unexpected end of clause',Stream,Line] ]. [ 'SYNTAX ERROR ~a, stream ~w, near line ~d.' - ['Unexpected end of clause',Stream,Line] ].
system_message(error(syntax_error(read(_),_,_,Term,Pos,Start,File), Where)) --> system_message(error(syntax_error(_), [syntax_error(read(_),_,_,Term,Pos,Start,File)|_])) -->
{ Term = [_|_] }, { Term = [_|_] },
['~w' - [Where]], ['SYNTAX ERROR' - []],
syntax_error_line(File, Start, Pos), syntax_error_line(File, Start, Pos),
syntax_error_term(10, Pos, Term), syntax_error_term(10, Pos, Term),
[ '.' ]. [ '.' ].