fix syntax error messages
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2275 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
25
C/iopreds.c
25
C/iopreds.c
@@ -1592,7 +1592,7 @@ PlUnGetc (int sno)
|
||||
s->stream_getc = PlGetc;
|
||||
s->stream_gets = PlGetsFunc();
|
||||
}
|
||||
return(post_process_read_char(ch, s));
|
||||
return(ch);
|
||||
}
|
||||
|
||||
/* give back 0376+ch */
|
||||
@@ -3590,7 +3590,7 @@ clean_vars(VarEntry *p)
|
||||
}
|
||||
|
||||
static Term
|
||||
syntax_error (TokEntry * tokptr)
|
||||
syntax_error (TokEntry * tokptr, int sno)
|
||||
{
|
||||
Term info;
|
||||
int count = 0, out = 0;
|
||||
@@ -3687,6 +3687,7 @@ syntax_error (TokEntry * tokptr)
|
||||
tf[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("read"),1),1,&ARG2);
|
||||
{
|
||||
Term t[3];
|
||||
|
||||
t[0] = MkIntegerTerm(start);
|
||||
t[1] = MkIntegerTerm(err);
|
||||
t[2] = MkIntegerTerm(end);
|
||||
@@ -3695,7 +3696,8 @@ syntax_error (TokEntry * tokptr)
|
||||
tf[2] = MkAtomTerm(Yap_LookupAtom("\n<==== HERE ====>\n"));
|
||||
tf[4] = MkIntegerTerm(out);
|
||||
tf[5] = MkIntegerTerm(err);
|
||||
return(Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("syntax_error"),6),6,tf));
|
||||
tf[6] = StreamName(sno);
|
||||
return(Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("syntax_error"),7),7,tf));
|
||||
}
|
||||
|
||||
Int
|
||||
@@ -3932,7 +3934,7 @@ static Int
|
||||
/* try again */
|
||||
goto repeat_cycle;
|
||||
} else {
|
||||
Term terr = syntax_error(tokstart);
|
||||
Term terr = syntax_error(tokstart, inp_stream);
|
||||
if (Yap_ErrorMessage == NULL)
|
||||
Yap_ErrorMessage = "SYNTAX ERROR";
|
||||
|
||||
@@ -4284,7 +4286,7 @@ p_set_stream_position (void)
|
||||
Stream[sno].stream_gets = PlGetsFunc();
|
||||
/* reset the counters */
|
||||
Stream[sno].linepos = 0;
|
||||
Stream[sno].linecount = 0;
|
||||
Stream[sno].linecount = 1;
|
||||
Stream[sno].charcount = 0;
|
||||
}
|
||||
UNLOCK(Stream[sno].streamlock);
|
||||
@@ -5938,33 +5940,40 @@ Yap_StringToTerm(char *s,Term *tp)
|
||||
|
||||
if (sno < 0)
|
||||
return FALSE;
|
||||
UNLOCK(Stream[sno].streamlock);
|
||||
TR_before_parse = TR;
|
||||
tokstart = Yap_tokptr = Yap_toktide = Yap_tokenizer(sno);
|
||||
/* cannot actually use CloseStream, because we didn't allocate the buffer */
|
||||
Stream[sno].status = Free_Stream_f;
|
||||
if (tokstart == NIL && tokstart->Tok == Ord (eot_tok)) {
|
||||
if (tp) {
|
||||
*tp = MkAtomTerm(Yap_LookupAtom("end of file found before end of term"));
|
||||
}
|
||||
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
||||
/* cannot actually use CloseStream, because we didn't allocate the buffer */
|
||||
Stream[sno].status = Free_Stream_f;
|
||||
return FALSE;
|
||||
} else if (Yap_ErrorMessage) {
|
||||
if (tp) {
|
||||
*tp = MkAtomTerm(Yap_LookupAtom(Yap_ErrorMessage));
|
||||
}
|
||||
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
||||
/* cannot actually use CloseStream, because we didn't allocate the buffer */
|
||||
Stream[sno].status = Free_Stream_f;
|
||||
return FALSE;
|
||||
}
|
||||
t = Yap_Parse();
|
||||
TR = TR_before_parse;
|
||||
if (Yap_ErrorMessage) {
|
||||
if (tp) {
|
||||
*tp = syntax_error(tokstart);
|
||||
*tp = syntax_error(tokstart, sno);
|
||||
}
|
||||
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
||||
/* cannot actually use CloseStream, because we didn't allocate the buffer */
|
||||
Stream[sno].status = Free_Stream_f;
|
||||
return FALSE;
|
||||
}
|
||||
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
||||
/* cannot actually use CloseStream, because we didn't allocate the buffer */
|
||||
Stream[sno].status = Free_Stream_f;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
22
C/stdpreds.c
22
C/stdpreds.c
@@ -11,8 +11,11 @@
|
||||
* File: stdpreds.c *
|
||||
* comments: General-purpose C implemented system predicates *
|
||||
* *
|
||||
* Last rev: $Date: 2008-04-06 11:53:02 $,$Author: vsc $ *
|
||||
* Last rev: $Date: 2008-06-12 10:55:52 $,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $
|
||||
* Revision 1.130 2008/04/06 11:53:02 vsc
|
||||
* fix some restore bugs
|
||||
*
|
||||
* Revision 1.129 2008/03/15 12:19:33 vsc
|
||||
* fix flags
|
||||
*
|
||||
@@ -1843,16 +1846,17 @@ p_atom_split(void)
|
||||
}
|
||||
|
||||
static Term
|
||||
gen_syntax_error(char *s)
|
||||
gen_syntax_error(Atom InpAtom, char *s)
|
||||
{
|
||||
Term ts[6], ti[2];
|
||||
ti[0] = ARG1;
|
||||
ti[1] = ARG2;
|
||||
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom(s),2),2,ti);
|
||||
ts[1] = ts[4] = ts[5] = MkIntTerm(0);
|
||||
ts[2] = MkAtomTerm(Yap_LookupAtom("number syntax"));
|
||||
ts[2] = MkAtomTerm(Yap_LookupAtom("expected number syntax"));
|
||||
ts[3] = TermNil;
|
||||
return(Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("syntax_error"),6),6,ts));
|
||||
ts[6] = MkAtomTerm(InpAtom);
|
||||
return(Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("syntax_error"),7),7,ts));
|
||||
}
|
||||
|
||||
static Int
|
||||
@@ -1991,7 +1995,7 @@ p_number_chars(void)
|
||||
}
|
||||
*s++ = '\0';
|
||||
if ((NewT = get_num(String)) == TermNil) {
|
||||
Yap_Error(SYNTAX_ERROR, gen_syntax_error("number_chars"), "while scanning %s", String);
|
||||
Yap_Error(SYNTAX_ERROR, gen_syntax_error(Yap_LookupAtom(String), "number_chars"), "while scanning %s", String);
|
||||
return (FALSE);
|
||||
}
|
||||
return (Yap_unify(ARG1, NewT));
|
||||
@@ -2060,7 +2064,7 @@ p_number_atom(void)
|
||||
}
|
||||
s = RepAtom(AtomOfTerm(t))->StrOfAE;
|
||||
if ((NewT = get_num(s)) == TermNil) {
|
||||
Yap_Error(SYNTAX_ERROR, gen_syntax_error("number_atom"), "while scanning %s", s);
|
||||
Yap_Error(SYNTAX_ERROR, gen_syntax_error(Yap_LookupAtom(String), "number_atom"), "while scanning %s", s);
|
||||
return (FALSE);
|
||||
}
|
||||
return (Yap_unify(ARG1, NewT));
|
||||
@@ -2155,7 +2159,7 @@ p_number_codes(void)
|
||||
}
|
||||
*s++ = '\0';
|
||||
if ((NewT = get_num(String)) == TermNil) {
|
||||
Yap_Error(SYNTAX_ERROR, gen_syntax_error("number_codes"), "while scanning %s", String);
|
||||
Yap_Error(SYNTAX_ERROR, gen_syntax_error(Yap_LookupAtom(String), "number_codes"), "while scanning %s", String);
|
||||
return (FALSE);
|
||||
}
|
||||
return (Yap_unify(ARG1, NewT));
|
||||
@@ -2217,12 +2221,12 @@ p_atom_number(void)
|
||||
}
|
||||
at = AtomOfTerm(t);
|
||||
if (IsWideAtom(at)) {
|
||||
Yap_Error(SYNTAX_ERROR, gen_syntax_error("number_codes"), "while scanning %S", RepAtom(at)->WStrOfAE);
|
||||
Yap_Error(SYNTAX_ERROR, gen_syntax_error(at, "number_codes"), "while scanning %S", RepAtom(at)->WStrOfAE);
|
||||
return FALSE;
|
||||
}
|
||||
s = RepAtom(at)->StrOfAE; /* alloc temp space on Trail */
|
||||
if ((NewT = get_num(s)) == TermNil) {
|
||||
Yap_Error(SYNTAX_ERROR, gen_syntax_error("atom_number"), "while scanning %s", s);
|
||||
Yap_Error(SYNTAX_ERROR, gen_syntax_error(at, "atom_number"), "while scanning %s", s);
|
||||
return FALSE;
|
||||
}
|
||||
return Yap_unify(ARG2, NewT);
|
||||
|
Reference in New Issue
Block a user