fix error handling in read to do what it should do.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@517 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
f19c10ca6c
commit
3a660ed7af
36
C/iopreds.c
36
C/iopreds.c
@ -2836,7 +2836,7 @@ p_get_read_error_handler(void)
|
|||||||
|
|
||||||
static Int
|
static Int
|
||||||
p_read (void)
|
p_read (void)
|
||||||
{ /* '$read'(+Flag,?Term,?Vars) */
|
{ /* '$read'(+Flag,?Term,?Vars,-Err) */
|
||||||
Term t, v;
|
Term t, v;
|
||||||
TokEntry *tokstart, *fast_tokenizer (void);
|
TokEntry *tokstart, *fast_tokenizer (void);
|
||||||
#if EMACS
|
#if EMACS
|
||||||
@ -2894,16 +2894,26 @@ p_read (void)
|
|||||||
}
|
}
|
||||||
TR = old_TR;
|
TR = old_TR;
|
||||||
if (parser_error_style == QUIET_ON_PARSER_ERROR) {
|
if (parser_error_style == QUIET_ON_PARSER_ERROR) {
|
||||||
|
/* just fail */
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
} else if (parser_error_style == CONTINUE_ON_PARSER_ERROR) {
|
||||||
if (ErrorMessage) {
|
ErrorMessage = NULL;
|
||||||
Error(SYNTAX_ERROR,syntax_error(tokstart),ErrorMessage);
|
/* try again */
|
||||||
return(FALSE);
|
goto repeat_cycle;
|
||||||
} else if (parser_error_style == FAIL_ON_PARSER_ERROR) {
|
|
||||||
return(FALSE);
|
|
||||||
} else {
|
} else {
|
||||||
Error(SYNTAX_ERROR,syntax_error(tokstart),"SYNTAX ERROR");
|
Term terr = syntax_error(tokstart);
|
||||||
return(FALSE);
|
if (ErrorMessage == NULL)
|
||||||
|
ErrorMessage = "SYNTAX ERROR";
|
||||||
|
|
||||||
|
if (parser_error_style == EXCEPTION_ON_PARSER_ERROR) {
|
||||||
|
Error(SYNTAX_ERROR,terr,ErrorMessage);
|
||||||
|
return(FALSE);
|
||||||
|
} else /* FAIL ON PARSER ERROR */ {
|
||||||
|
Term t[2];
|
||||||
|
t[0] = terr;
|
||||||
|
t[1] = MkAtomTerm(LookupAtom(ErrorMessage));
|
||||||
|
return(unify(ARG4,MkApplTerm(MkFunctor(LookupAtom("error"),2),2,t)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* parsing succeeded */
|
/* parsing succeeded */
|
||||||
@ -2939,12 +2949,12 @@ p_read (void)
|
|||||||
|
|
||||||
static Int
|
static Int
|
||||||
p_read2 (void)
|
p_read2 (void)
|
||||||
{ /* '$read2'(+Flag,?Term,?Vars,+Stream) */
|
{ /* '$read2'(+Flag,?Term,?Vars,-Err,+Stream) */
|
||||||
int old_c_stream = c_input_stream;
|
int old_c_stream = c_input_stream;
|
||||||
Int out;
|
Int out;
|
||||||
|
|
||||||
/* needs to change c_output_stream for write */
|
/* needs to change c_output_stream for write */
|
||||||
c_input_stream = CheckStream (ARG4, Input_Stream_f, "read/3");
|
c_input_stream = CheckStream (ARG5, Input_Stream_f, "read/3");
|
||||||
if (c_input_stream == -1) {
|
if (c_input_stream == -1) {
|
||||||
c_input_stream = old_c_stream;
|
c_input_stream = old_c_stream;
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
@ -4858,8 +4868,8 @@ InitIOPreds(void)
|
|||||||
InitCPred ("$put_byte", 2, p_put_byte, SafePredFlag|SyncPredFlag);
|
InitCPred ("$put_byte", 2, p_put_byte, SafePredFlag|SyncPredFlag);
|
||||||
InitCPred ("$set_read_error_handler", 1, p_set_read_error_handler, SafePredFlag|SyncPredFlag);
|
InitCPred ("$set_read_error_handler", 1, p_set_read_error_handler, SafePredFlag|SyncPredFlag);
|
||||||
InitCPred ("$get_read_error_handler", 1, p_get_read_error_handler, SafePredFlag|SyncPredFlag);
|
InitCPred ("$get_read_error_handler", 1, p_get_read_error_handler, SafePredFlag|SyncPredFlag);
|
||||||
InitCPred ("$read", 3, p_read, SyncPredFlag);
|
InitCPred ("$read", 4, p_read, SyncPredFlag);
|
||||||
InitCPred ("$read", 4, p_read2, SyncPredFlag);
|
InitCPred ("$read", 5, p_read2, SyncPredFlag);
|
||||||
InitCPred ("$set_input", 1, p_set_input, SafePredFlag|SyncPredFlag);
|
InitCPred ("$set_input", 1, p_set_input, SafePredFlag|SyncPredFlag);
|
||||||
InitCPred ("$set_output", 1, p_set_output, SafePredFlag|SyncPredFlag);
|
InitCPred ("$set_output", 1, p_set_output, SafePredFlag|SyncPredFlag);
|
||||||
InitCPred ("$skip", 2, p_skip, SafePredFlag|SyncPredFlag);
|
InitCPred ("$skip", 2, p_skip, SafePredFlag|SyncPredFlag);
|
||||||
|
10
pl/boot.yap
10
pl/boot.yap
@ -122,10 +122,12 @@ read_sig.
|
|||||||
|
|
||||||
/* main execution loop */
|
/* main execution loop */
|
||||||
'$read_vars'(Stream,T,V) :-
|
'$read_vars'(Stream,T,V) :-
|
||||||
current_input(Old),
|
'$read'(true,T,V,Err,Stream),
|
||||||
'$set_input'(Stream),
|
(nonvar(Err) ->
|
||||||
'$read'(true,T,V),
|
'$print_message'(error,Err), fail
|
||||||
'$set_input'(Old).
|
;
|
||||||
|
true
|
||||||
|
).
|
||||||
|
|
||||||
% reset alarms when entering top-level.
|
% reset alarms when entering top-level.
|
||||||
'$enter_top_level' :-
|
'$enter_top_level' :-
|
||||||
|
26
pl/yio.yap
26
pl/yio.yap
@ -314,22 +314,42 @@ told :- current_output(Stream), '$close'(Stream), set_output(user).
|
|||||||
|
|
||||||
/* Term IO */
|
/* Term IO */
|
||||||
|
|
||||||
read(T) :- '$read'(false,T,[]).
|
read(T) :-
|
||||||
|
'$read'(false,T,V,Err),
|
||||||
|
(nonvar(Err) ->
|
||||||
|
'$print_message'(error,Err), fail
|
||||||
|
;
|
||||||
|
true
|
||||||
|
).
|
||||||
|
|
||||||
read(Stream,T) :-
|
read(Stream,T) :-
|
||||||
|
'$read'(false,T,V,Err,Stream),
|
||||||
|
(nonvar(Err) ->
|
||||||
|
'$print_message'(error,Err), fail
|
||||||
|
;
|
||||||
|
true
|
||||||
|
).
|
||||||
'$read'(false,T,_,Stream).
|
'$read'(false,T,_,Stream).
|
||||||
|
|
||||||
|
|
||||||
read_term(T, Options) :-
|
read_term(T, Options) :-
|
||||||
'$check_io_opts'(Options,read_term(T, Options)),
|
'$check_io_opts'(Options,read_term(T, Options)),
|
||||||
'$preprocess_read_terms_options'(Options),
|
'$preprocess_read_terms_options'(Options),
|
||||||
'$read'(true,T,VL),
|
'$read_vars'(T,VL),
|
||||||
'$postprocess_read_terms_options'(Options, T, VL).
|
'$postprocess_read_terms_options'(Options, T, VL).
|
||||||
|
|
||||||
|
'$read_vars'(T,V) :-
|
||||||
|
'$read'(true,T,V,Err),
|
||||||
|
(nonvar(Err) ->
|
||||||
|
'$print_message'(error,Err), fail
|
||||||
|
;
|
||||||
|
true
|
||||||
|
).
|
||||||
|
|
||||||
read_term(Stream, T, Options) :-
|
read_term(Stream, T, Options) :-
|
||||||
'$check_io_opts'(Options,read_term(T, Options)),
|
'$check_io_opts'(Options,read_term(T, Options)),
|
||||||
'$preprocess_read_terms_options'(Options),
|
'$preprocess_read_terms_options'(Options),
|
||||||
'$read'(true,T,VL,Stream),
|
'$read_vars'(Strem,T,VL),
|
||||||
'$postprocess_read_terms_options'(Options, T, VL).
|
'$postprocess_read_terms_options'(Options, T, VL).
|
||||||
|
|
||||||
%
|
%
|
||||||
|
Reference in New Issue
Block a user