From e1f618739522102289e883476444ce5c9c31e356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Thu, 3 May 2012 00:16:11 +0100 Subject: [PATCH] make syntax error standard. --- C/errors.c | 7 ++++++- C/iopreds.c | 5 +++-- pl/errors.yap | 9 --------- pl/messages.yap | 8 ++++---- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/C/errors.c b/C/errors.c index 372462193..8c7d2fe6d 100644 --- a/C/errors.c +++ b/C/errors.c @@ -1431,9 +1431,11 @@ Yap_Error(yap_error_number type, Term where, char *format,...) case SYNTAX_ERROR: { int i; + Term ti[1]; i = strlen(tmpbuf); - nt[0] = where; + ti[0] = MkAtomTerm(AtomSyntaxError); + nt[0] = Yap_MkApplTerm(FunctorShortSyntaxError, 1, ti); psize -= i; fun = FunctorError; serious = TRUE; @@ -1807,6 +1809,9 @@ E); LOCAL_Error_Size = 0L; } nt[1] = MkPairTerm(MkAtomTerm(Yap_LookupAtom(tmpbuf)), stack_dump); + if (type == SYNTAX_ERROR) { + nt[1] = MkPairTerm(where, nt[1]); + } } } if (serious) { diff --git a/C/iopreds.c b/C/iopreds.c index 6f6a3acf2..0f964d340 100644 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -383,8 +383,9 @@ GenerateSyntaxError(Term *tp, TokEntry *tokstart, IOSTREAM *sno USES_REGS) if (tp) { Term et[2]; Term t = MkVarTerm(); - et[0] = syntax_error(tokstart, sno, &t); - et[1] = MkAtomTerm(Yap_LookupAtom("Syntax error")); + et[1] = MkPairTerm(syntax_error(tokstart, sno, &t), TermNil); + t = MkAtomTerm(AtomSyntaxError); + et[0] = Yap_MkApplTerm(FunctorShortSyntaxError,1,&t); *tp = Yap_MkApplTerm(FunctorError, 2, et); } } diff --git a/pl/errors.yap b/pl/errors.yap index ae064127f..fa55adaa5 100644 --- a/pl/errors.yap +++ b/pl/errors.yap @@ -255,8 +255,6 @@ print_message(Severity, Term) :- '$print_system_message'(Term, Severity, Lines) ), !. 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)) :- !, format(user_error,' % ~a ~a~n',[A,F]). print_message(_, loaded(A, F, _, Time, Space)) :- !, @@ -284,13 +282,6 @@ print_message(_, Term) :- current_prolog_flag(verbose, silent), !. '$print_system_message'(_, banner, _) :- 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) :- '$messages':prefix(Level, LinePrefix, Stream, Prefix), '$messages':file_location(Prefix, LinesF, Lines), !, diff --git a/pl/messages.yap b/pl/messages.yap index 909548a82..2204299f1 100644 --- a/pl/messages.yap +++ b/pl/messages.yap @@ -283,14 +283,14 @@ system_message(error(resource_error(trail), Where)) --> [ 'RESOURCE ERROR- not enough trail space' - [Where] ]. system_message(error(signal(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] ]. % 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] ]. -system_message(error(syntax_error(read(_),_,_,Term,Pos,Start,File), Where)) --> +system_message(error(syntax_error(_), [syntax_error(read(_),_,_,Term,Pos,Start,File)|_])) --> { Term = [_|_] }, - ['~w' - [Where]], + ['SYNTAX ERROR' - []], syntax_error_line(File, Start, Pos), syntax_error_term(10, Pos, Term), [ '.' ].