XyMerge /home/vsc/yap

This commit is contained in:
Vítor Santos Costa 2018-10-22 15:31:45 +01:00
commit 0d47af2ad9
14 changed files with 756 additions and 703 deletions

View File

@ -224,7 +224,7 @@ static int stack_overflow(PredEntry *pe, CELL *env, yamop *cp,
Yap_get_signal(YAP_STOVF_SIGNAL)) {
S = (CELL *)pe;
if (!Yap_locked_gc(nargs, env, cp)) {
Yap_NilError(RESOURCE_ERROR_STACK, LOCAL_ErrorMessage);
Yap_NilError(RESOURCE_ERROR_STACK, "stack overflow: gc failed");
return 0;
}
return 1;
@ -239,7 +239,7 @@ static int code_overflow(CELL *yenv USES_REGS) {
/* do a garbage collection first to check if we can recover memory */
if (!Yap_locked_growheap(false, 0, NULL)) {
Yap_NilError(RESOURCE_ERROR_HEAP, "YAP failed to grow heap: %s",
LOCAL_ErrorMessage);
"malloc/mmap failed");
return 0;
}
CACHE_A1();
@ -689,7 +689,7 @@ static int interrupt_deallocate(USES_REGS1) {
return rc;
}
if (!Yap_locked_gc(0, ENV, YESCODE)) {
Yap_NilError(RESOURCE_ERROR_STACK, LOCAL_ErrorMessage);
Yap_NilError(RESOURCE_ERROR_STACK, "stack overflow: gc failed");
}
S = ASP;
S[E_CB] = (CELL)(LCL0 - cut_b);

View File

@ -1102,7 +1102,7 @@
PP = NULL;
#endif
if (!Yap_gc(3, ENV, CP)) {
Yap_NilError(RESOURCE_ERROR_STACK, LOCAL_ErrorMessage);
Yap_NilError(RESOURCE_ERROR_STACK, "stack overflow: gc failed");
FAIL();
}
#if defined(YAPOR) || defined(THREADS)
@ -1226,7 +1226,7 @@
PREG = NEXTOP(PREG,Osbpa);
saveregs();
if (!Yap_gcl(sz, arity, YENV, PREG)) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs();
FAIL();
} else {
@ -10927,7 +10927,7 @@
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxx),Osbpp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs();
JMPNext();
} else {
@ -11044,7 +11044,7 @@
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxc),Osbpp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs();
JMPNext();
} else {
@ -11154,7 +11154,7 @@
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gc(0, YREG, NEXTOP(NEXTOP(PREG,xxn),Osbpp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs();
JMPNext();
} else {
@ -11261,7 +11261,7 @@
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxx),Osbpp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs();
JMPNext();
} else {
@ -11388,7 +11388,7 @@
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxc),Osbpp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs();
JMPNext();
} else {
@ -11516,7 +11516,7 @@
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxn),Osbpp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed");
setregs();
JMPNext();
} else {
@ -11892,7 +11892,7 @@
/* make sure we have something to show for our trouble */
saveregs();
if (!Yap_gcl((1+d1)*sizeof(CELL), 3, YREG, NEXTOP(NEXTOP(PREG,e),Osbmp))) {
Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage);
Yap_NilError(RESOURCE_ERROR_STACK,"stack overflow: gc failed" );
setregs();
JMPNext();
} else {

View File

@ -35,7 +35,7 @@
#define set_key_b(k, ks, q, i, t) \
if (strcmp(ks, q) == 0) { \
i->k = t == TermTrue ? true : false; \
i->k = ( t == TermTrue ? true : false); \
return i->k || t == TermFalse; \
}
@ -67,18 +67,18 @@ static bool setErr(const char *q, yap_error_descriptor_t *i, Term t) {
set_key_s(errorFunction, "errorFunction", q, i, t);
set_key_s(errorFile, "errorFile", q, i, t);
set_key_i(prologPredLine, "prologPredLine", q, i, t);
set_key_i(prologPredFirstLine, "prologPredFirstLine", q, i, t);
set_key_i(prologPredLastLine, "prologPredLastLine", q, i, t);
set_key_s(prologPredName, "prologPredName", q, i, t);
set_key_i(prologPredArity, "prologPredArity", q, i, t);
set_key_s(prologPredModule, "prologPredModule", q, i, t);
set_key_s(prologPredFile, "prologPredFile", q, i, t);
set_key_i(prologParserPos, "prologParserPos", q, i, t);
set_key_i(prologParserLine, "prologParserLine", q, i, t);
set_key_i(prologParserFirstLine, "prologParserFirstLine", q, i, t);
set_key_i(prologParserLastLine, "prologParserLastLine", q, i, t);
set_key_s(prologParserText, "prologParserText", q, i, t);
set_key_s(prologParserFile, "prologParserFile", q, i, t);
set_key_i(parserPos, "parserPos", q, i, t);
set_key_i(parserLine, "parserLine", q, i, t);
set_key_i(parserFirstLine, "parserFirstLine", q, i, t);
set_key_i(parserLastLine, "parserLastLine", q, i, t);
set_key_s(parserTextA, "parserTextA", q, i, t);
set_key_s(parserTextB, "parserTextB", q, i, t);
set_key_s(parserFile, "parserFile", q, i, t);
set_key_b(parserReadingCode, "parserReadingcode", q, i, t);
set_key_b(prologConsulting, "prologConsulting", q, i, t);
set_key_s(culprit, "culprit", q, i, t);
set_key_s(errorMsg, "errorMsg", q, i, t);
@ -116,18 +116,18 @@ static Term queryErr(const char *q, yap_error_descriptor_t *i) {
query_key_s(errorFunction, "errorFunction", q, i);
query_key_s(errorFile, "errorFile", q, i);
query_key_i(prologPredLine, "prologPredLine", q, i);
query_key_i(prologPredFirstLine, "prologPredFirstLine", q, i);
query_key_i(prologPredLastLine, "prologPredLastLine", q, i);
query_key_s(prologPredName, "prologPredName", q, i);
query_key_i(prologPredArity, "prologPredArity", q, i);
query_key_s(prologPredModule, "prologPredModule", q, i);
query_key_s(prologPredFile, "prologPredFile", q, i);
query_key_i(prologParserPos, "prologParserPos", q, i);
query_key_i(prologParserLine, "prologParserLine", q, i);
query_key_i(prologParserFirstLine, "prologParserFirstLine", q, i);
query_key_i(prologParserLastLine, "prologParserLastLine", q, i);
query_key_s(prologParserText, "prologParserText", q, i);
query_key_s(prologParserFile, "prologParserFile", q, i);
query_key_i(parserPos, "parserPos", q, i);
query_key_i(parserLine, "parserLine", q, i);
query_key_i(parserFirstLine, "parserFirstLine", q, i);
query_key_i(parserLastLine, "parserLastLine", q, i);
query_key_s(parserTextA, "parserTextA", q, i);
query_key_s(parserTextB, "parserTextB", q, i);
query_key_s(parserFile, "parserFile", q, i);
query_key_b(parserReadingCode, "parserReadingCode", q, i);
query_key_b(prologConsulting, "prologConsulting", q, i);
query_key_t(culprit, "culprit", q, i);
query_key_s(errorMsg, "errorMsg", q, i);
@ -162,18 +162,18 @@ static void printErr(yap_error_descriptor_t *i) {
print_key_s("errorFunction", i->errorFunction);
print_key_s("errorFile", i->errorFile);
print_key_i("prologPredLine", i->prologPredLine);
print_key_i("prologPredFirstLine", i->prologPredFirstLine);
print_key_i("prologPredLastLine", i->prologPredLastLine);
print_key_s("prologPredName", i->prologPredName);
print_key_i("prologPredArity", i->prologPredArity);
print_key_s("prologPredModule", i->prologPredModule);
print_key_s("prologPredFile", i->prologPredFile);
print_key_i("prologParserPos", i->prologParserPos);
print_key_i("prologParserLine", i->prologParserLine);
print_key_i("prologParserFirstLine", i->prologParserFirstLine);
print_key_i("prologParserLastLine", i->prologParserLastLine);
print_key_s("prologParserText", i->prologParserText);
print_key_s("prologParserFile", i->prologParserFile);
print_key_i("parserPos", i->parserPos);
print_key_i("parserLine", i->parserLine);
print_key_i("parserFirstLine", i->parserFirstLine);
print_key_i("parserLastLine", i->parserLastLine);
print_key_s("parserTextA", i->parserTextA);
print_key_s("parserTextB", i->parserTextB);
print_key_s("parserFile", i->parserFile);
print_key_b("parserReadingCode", i->parserReadingCode);
print_key_b("prologConsulting", i->prologConsulting);
print_key_s("culprit", i->culprit);
if (i->errorMsgLen) {
@ -220,18 +220,18 @@ static Term err2list(yap_error_descriptor_t *i) {
o = add_key_s("errorFunction", i->errorFunction, o);
o = add_key_s("errorFile", i->errorFile, o);
o = add_key_i("prologPredLine", i->prologPredLine, o);
o = add_key_i("prologPredFirstLine", i->prologPredFirstLine, o);
o = add_key_i("prologPredLastLine", i->prologPredLastLine, o);
o = add_key_s("prologPredName", i->prologPredName, o);
o = add_key_i("prologPredArity", i->prologPredArity, o);
o = add_key_s("prologPredModule", i->prologPredModule, o);
o = add_key_s("prologPredFile", i->prologPredFile, o);
o = add_key_i("prologParserPos", i->prologParserPos, o);
o = add_key_i("prologParserLine", i->prologParserLine, o);
o = add_key_i("prologParserFirstLine", i->prologParserFirstLine, o);
o = add_key_i("prologParserLastLine", i->prologParserLastLine, o);
o = add_key_s("prologParserText", i->prologParserText, o);
o = add_key_s("prologParserFile", i->prologParserFile, o);
o = add_key_i("parserPos", i->parserPos, o);
o = add_key_i("parserLine", i->parserLine, o);
o = add_key_i("parserFirstLine", i->parserFirstLine, o);
o = add_key_i("parserLastLine", i->parserLastLine, o);
o = add_key_s("parserTextA", i->parserTextA, o);
o = add_key_s("parserTextB", i->parserTextB, o);
o = add_key_s("parserFile", i->parserFile, o);
o = add_key_b("parserReadingCode", i->parserReadingCode, o);
o = add_key_b("prologConsulting", i->prologConsulting, o);
o = add_key_s("culprit", i->culprit, o);
if (i->errorMsgLen) {
@ -317,7 +317,7 @@ void Yap_InitError__(const char *file, const char *function, int lineno,
if (fmt) {
LOCAL_Error_Size = strlen(tmpbuf);
LOCAL_ActiveError->errorMsg = malloc(LOCAL_Error_Size + 1);
strcpy(LOCAL_ActiveError->errorMsg, tmpbuf);
strcpy((char *)LOCAL_ActiveError->errorMsg, tmpbuf);
} else {
LOCAL_Error_Size = 0;
}
@ -334,6 +334,7 @@ bool Yap_PrintWarning(Term twarning) {
Term ts[2], err;
if (LOCAL_PrologMode & InErrorMode && LOCAL_ActiveError &&
LOCAL_ActiveError->errorClass != WARNING &&
(err = LOCAL_ActiveError->errorNo)) {
fprintf(stderr, "%% Warning %s while processing error: %s %s\n",
Yap_TermToBuffer(twarning,
@ -423,9 +424,7 @@ int Yap_SWIHandleError(const char *s, ...) {
yap_error_number err = LOCAL_Error_TYPE;
char *serr;
if (LOCAL_ErrorMessage) {
serr = LOCAL_ErrorMessage;
} else {
if (s) {
serr = (char *)s;
}
switch (err) {
@ -575,8 +574,11 @@ static char tmpbuf[YAP_BUF_SIZE];
#include "YapErrors.h"
bool Yap_pushErrorContext(bool pass, yap_error_descriptor_t *new_error) {
/// add a new error descriptor, either to the top of the stack,
/// or replacing the top;
bool Yap_pushErrorContext(bool link , yap_error_descriptor_t *new_error) {
memset(new_error, 0, sizeof(yap_error_descriptor_t));
if (link)
new_error->top_error = LOCAL_ActiveError;
LOCAL_ActiveError = new_error;
return true;
@ -645,6 +647,16 @@ void Yap_ThrowExistingError(void) {
Yap_exit(5);
}
Term Yap_MkFullError(void)
{
yap_error_descriptor_t *i = Yap_local.ActiveError;
i->errorAsText = Yap_errorName( i->errorNo );
i->errorClass = Yap_errorClass( i-> errorNo );
i->classAsText = Yap_errorClassName(i->errorClass);
return mkerrort(i->errorNo, TermNil , MkSysError(i) );
}
bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
const char *function, int lineno, yap_error_number type,
Term where, const char *s) {
@ -656,9 +668,9 @@ bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
r->culprit = Yap_TermToBuffer(
where, Quote_illegal_f | Ignore_ops_f);
}
if (LOCAL_consult_level > 0) {
r->prologParserFile = Yap_ConsultingFile(PASS_REGS1)->StrOfAE;
r->prologParserLine = Yap_source_line_no();
if (type != SYNTAX_ERROR && LOCAL_consult_level > 0) {
r->parserFile = Yap_ConsultingFile(PASS_REGS1)->StrOfAE;
r->parserLine = Yap_source_line_no();
}
r->errorNo = type;
r->errorAsText = Yap_errorName(type);
@ -670,6 +682,7 @@ bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
LOCAL_PrologMode |= InErrorMode;
Yap_ClearExs();
// first, obtain current location
// sprintf(LOCAL_FileNameBuf, "%s:%d in C-function %s ", file, lineno,
// function);
// tf = MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf));
@ -694,13 +707,11 @@ bool Yap_MkErrorRecord(yap_error_descriptor_t *r, const char *file,
}
// fprintf(stderr, "warning: ");
if (s && s[0]) {
char *ns;
r->errorMsgLen = strlen(s) + 1;
r->errorMsg = malloc(r->errorMsgLen);
strcpy(r->errorMsg, s);
} else if (LOCAL_ErrorMessage && LOCAL_ErrorMessage[0]) {
r->errorMsgLen = strlen(LOCAL_ErrorMessage) + 1;
r->errorMsg = malloc(r->errorMsgLen);
strcpy(r->errorMsg, LOCAL_ErrorMessage);
ns = malloc(r->errorMsgLen);
strcpy(ns, s);
r->errorMsg = ns;
} else {
r->errorMsgLen = 0;
r->errorMsg = 0;

View File

@ -60,12 +60,12 @@ static void syntax_msg(const char *msg, ...) {
va_list ap;
if (!LOCAL_ErrorMessage ||
(LOCAL_Error_TYPE == SYNTAX_ERROR &&
LOCAL_tokptr->TokPos < LOCAL_ActiveError->prologParserPos)) {
LOCAL_tokptr->TokPos < LOCAL_ActiveError->parserPos)) {
if (!LOCAL_ErrorMessage) {
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE + 1);
}
LOCAL_ActiveError->prologParserLine = LOCAL_tokptr->TokLine;
LOCAL_ActiveError->prologParserPos = LOCAL_tokptr->TokPos;
LOCAL_ActiveError->parserLine = LOCAL_tokptr->TokLine;
LOCAL_ActiveError->parserPos = LOCAL_tokptr->TokPos;
va_start(ap, msg);
vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, msg, ap);
va_end(ap);
@ -911,12 +911,17 @@ Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) {
CACHE_REGS
// ensure that if we throw an exception
// t will be 0.
LOCAL_ActiveError->errorMsg=NULL;
LOCAL_ActiveError->errorMsgLen=0;
Volatile Term t = 0;
JMPBUFF FailBuff;
yhandle_t sls = Yap_StartSlots();
LOCAL_ErrorMessage = NULL;
LOCAL_toktide = LOCAL_tokptr;
if (!sigsetjmp(FailBuff.JmpBuff, 0)) {
LOCAL_ActiveError->errorMsg=NULL;
LOCAL_ActiveError->errorMsgLen=0;
t = ParseTerm(prio, &FailBuff, enc, cmod PASS_REGS);
#if DEBUG
@ -936,9 +941,13 @@ Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) {
if (LOCAL_tokptr != NULL && LOCAL_tokptr->Tok != Ord(eot_tok)) {
LOCAL_Error_TYPE = SYNTAX_ERROR;
if (LOCAL_tokptr->TokNext) {
LOCAL_ErrorMessage = "bracket or operator expected.";
size_t sz = strlen("bracket or operator expected.");
LOCAL_ErrorMessage =malloc(sz+1);
strncpy(LOCAL_ErrorMessage, "bracket or operator expected.", sz );
} else {
LOCAL_ErrorMessage = "term must end with . or EOF.";
size_t sz = strlen("term must end with . or EOF.");
LOCAL_ErrorMessage =malloc(sz+1);
strncpy(LOCAL_ErrorMessage,"term must end with . or EOF.", sz );
}
t = 0;
}

View File

@ -1124,7 +1124,7 @@ static Term clause_info(yamop *codeptr, PredEntry *pp) {
yap_error_descriptor_t *set_clause_info(yap_error_descriptor_t *t,
yamop *codeptr, PredEntry *pp) {
CACHE_REGS
Term ts[2];
void *begin;
if (pp->ArityOfPE == 0) {
t->prologPredName = AtomName((Atom)pp->FunctorOfPred);
@ -1138,36 +1138,18 @@ yap_error_descriptor_t *set_clause_info(yap_error_descriptor_t *t,
: "prolog");
t->prologPredFile = RepAtom(pp->src.OwnerFile)->StrOfAE;
if (codeptr->opc == UNDEF_OPCODE) {
t->prologPredFirstLine = 0;
t->prologPredLine = 0;
t->prologPredLastLine = 0;
return t;
} else if (pp->cs.p_code.NOfClauses) {
if ((t->prologPredCl = find_code_in_clause(pp, codeptr, &begin, NULL)) <=
if ((t->prologPredLine = find_code_in_clause(pp, codeptr, &begin, NULL)) <=
0) {
t->prologPredLine = 0;
} else {
t->prologPredLine = IntegerOfTerm(clause_loc(begin, pp));
}
if (pp->PredFlags & LogUpdatePredFlag) {
t->prologPredFirstLine =
clause_loc(ClauseCodeToLogUpdClause(pp->cs.p_code.FirstClause), pp);
t->prologPredLastLine =
clause_loc(ClauseCodeToLogUpdClause(pp->cs.p_code.LastClause), pp);
} else {
t->prologPredFirstLine = IntegerOfTerm(
ts[0] = clause_loc(
ClauseCodeToStaticClause(pp->cs.p_code.FirstClause), pp));
t->prologPredLastLine = IntegerOfTerm(
ts[1] = clause_loc(ClauseCodeToStaticClause(pp->cs.p_code.LastClause),
pp));
}
return t;
} else {
t->prologPredFirstLine = 0;
t->prologPredLine = t->errorLine;
t->prologPredLastLine = 0;
t->prologPredFile = t->errorFile;
return t;
}

View File

@ -990,7 +990,7 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
else
fprintf(stderr, "%s", out->val.c);
fprintf(stderr, "\n]\n"); */
pop_text_stack(l);
out->val.uc = pop_output_text_stack(l,out->val.uc);
return rc;
}

View File

@ -175,7 +175,10 @@ INLINE_ONLY char_kind_t chtype(Int ch) {
#endif
extern const char *Yap_tokText(void *tokptr);
extern Term Yap_tokRep(void *tokptr);
/// represent token *_tokptr_ in string s, maxlength is sz-1
///
/// conversion is based on token type.
extern Term Yap_tokRep(void *tokptrXS);
// standard strings

View File

@ -200,29 +200,47 @@ INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi, int line,
/// all we need to know about an error/throw
typedef struct s_yap_error_descriptor {
/// error identifier
yap_error_number errorNo;
/// kind of error: derived from errorNo;
yap_error_class_number errorClass;
/// if non-NULL: goal who caused error;
const char *errorGoal;
/// errorNo as text
const char *errorAsText;
/// errorClass as text
const char *classAsText;
/// c-code that generated the error
/// C-line
intptr_t errorLine;
/// C-function
const char *errorFunction;
/// C-file
const char *errorFile;
// struct error_prolog_source *errorSource;
intptr_t prologPredCl;
uintptr_t prologPredLine;
uintptr_t prologPredFirstLine;
uintptr_t prologPredLastLine;
/// Prolog predicate that caused the error: name
const char *prologPredName;
/// Prolog predicate that caused the error:arity
uintptr_t prologPredArity;
/// Prolog predicate that caused the error:module
const char *prologPredModule;
/// Prolog predicate that caused the error:line
const char *prologPredFile;
uintptr_t prologParserPos;
uintptr_t prologParserLine;
uintptr_t prologParserFirstLine;
uintptr_t prologParserLastLine;
const char *prologParserText;
const char *prologParserFile;
/// line where error clause defined
uintptr_t prologPredLine;
/// syntax and other parsing errors
uintptr_t parserPos;
uintptr_t parserFirstPos;
uintptr_t parserLastPos;
uintptr_t parserLine;
uintptr_t parserFirstLine;
uintptr_t parserLastLine;
const char *parserTextA;
const char *parserTextB;
const char *parserFile;
/// reading a clause, or called from read?
bool parserReadingCode;
/// whether we are consulting
bool prologConsulting;
const char *culprit;
YAP_Term errorRawTerm, rawExtraErrorTerm;
@ -242,6 +260,7 @@ INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi, int line,
extern void Yap_CatchError(void);
extern void Yap_ThrowExistingError(void);
extern YAP_Term Yap_MkFullError(void);
extern bool Yap_MkErrorRecord(
yap_error_descriptor_t * r, const char *file, const char *function,
int lineno, yap_error_number type, YAP_Term where, const char *msg);

View File

@ -32,6 +32,8 @@ ECLASS(SYSTEM_ERROR_CLASS, "system_error", 1)
ECLASS(TYPE_ERROR, "type_error", 2)
/// should be unbound
ECLASS(UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error", 1)
/// not quite an error, but almost
ECLASS(WARNING, "warning", 1)
/// user defined escape hatch
ECLASS(EVENT, "event", 1)
@ -196,7 +198,11 @@ E(TYPE_ERROR_REFERENCE, TYPE_ERROR, "reference")
E(TYPE_ERROR_STRING, TYPE_ERROR, "string")
E(TYPE_ERROR_TEXT, TYPE_ERROR, "text")
E(TYPE_ERROR_UBYTE, TYPE_ERROR, "ubyte")
E(TYPE_ERROR_UCHAR, TYPE_ERROR, "uchar")
E(TYPE_ERROR_UCHAR, TYPE_ERROR, "unsigned char")
E(WARNING_DISCONTIGUOUS, WARNING, "discontiguous")
E(WARNING_SINGLETONS, WARNING, "singletons")
E(WARNING_SYNTAX_ERROR, WARNING, "syntax_error")
E1(UNINSTANTIATION_ERROR, UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error")

View File

@ -278,32 +278,54 @@ static int format_print_str(Int sno, Int size, Int has_size, Term args,
while (*pt && (!has_size || size > 0)) {
utf8proc_int32_t ch;
if ((pt += get_utf8(pt, -1, &ch)) > 0) {
f_putc(sno, ch);
}
}
} else if (IsAtomTerm(args)) {
const unsigned char *pt = RepAtom(AtomOfTerm(args))->UStrOfAE;
while (*pt && (!has_size || size > 0)) {
utf8proc_int32_t ch;
if ((pt += get_utf8(pt, -1, &ch)) > 0) {
f_putc(sno, ch);
}
}
} else {
while (!has_size || size > 0) {
bool maybe_chars = true, maybe_codes = true;
if (IsVarTerm(args)) {
Yap_Error(INSTANTIATION_ERROR, args, "format/2");
Yap_ThrowError(INSTANTIATION_ERROR, args, "~s expects a bound argument");
return FALSE;
} else if (args == TermNil) {
return TRUE;
} else if (!IsPairTerm(args)) {
Yap_Error(TYPE_ERROR_LIST, args, "format/2");
Yap_ThrowError(TYPE_ERROR_TEXT, args, "format expects an atom, string, or list of codes or chars ");
return FALSE;
}
arghd = HeadOfTerm(args);
args = TailOfTerm(args);
if (IsVarTerm(arghd)) {
Yap_Error(INSTANTIATION_ERROR, arghd, "format/2");
Yap_ThrowError(INSTANTIATION_ERROR, arghd, "~s expects a bound argument");
return FALSE;
} else if (!IsIntTerm(arghd)) {
Yap_Error(TYPE_ERROR_LIST, arghd, "format/2");
return FALSE;
}
} else if (maybe_codes && IsIntTerm(arghd)) {
f_putc(sno, (int)IntOfTerm(arghd));
size--;
maybe_chars = false;
} else if (maybe_chars && IsAtomTerm(arghd)) {
unsigned char *fptr = RepAtom(AtomOfTerm(arghd))->UStrOfAE;
int ch;
fptr += get_utf8(fptr, -1, &ch);
if (fptr[0] != '\0') {
Yap_ThrowError(TYPE_ERROR_TEXT, arghd, "~s expects a list of chars ");
}
f_putc(sno, ch);
size--;
maybe_codes = false;
} else {
Yap_ThrowError(TYPE_ERROR_TEXT, arghd, "~s expects an atom, string, or list of codes or chars ");
return FALSE;
}
}
}
return TRUE;
@ -313,11 +335,11 @@ static Int format_copy_args(Term args, Term *targs, Int tsz) {
Int n = 0;
while (args != TermNil) {
if (IsVarTerm(args)) {
Yap_Error(INSTANTIATION_ERROR, args, "format/2");
Yap_ThrowError(INSTANTIATION_ERROR, args, "format/2");
return FORMAT_COPY_ARGS_ERROR;
}
if (!IsPairTerm(args)) {
Yap_Error(TYPE_ERROR_LIST, args, "format/2");
Yap_ThrowError(TYPE_ERROR_LIST, args, "format/2");
return FORMAT_COPY_ARGS_ERROR;
}
if (n == tsz)
@ -402,7 +424,7 @@ static Int doformat(volatile Term otail, volatile Term oargs,
*HR++ = otail;
if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
pop_text_stack(l);
Yap_Error(RESOURCE_ERROR_HEAP, otail, "format/2");
Yap_ThrowError(RESOURCE_ERROR_HEAP, otail, "format/2");
return false;
}
oargs = HR[-2];
@ -418,20 +440,20 @@ static Int doformat(volatile Term otail, volatile Term oargs,
targ = 0;
if (IsVarTerm(tail)) {
format_clean_up(sno0, sno, finfo );
Yap_Error(INSTANTIATION_ERROR, tail, "format/2");
Yap_ThrowError(INSTANTIATION_ERROR, tail, "format/2");
return (FALSE);
} else if ((fstr = Yap_TextToUTF8Buffer(tail))) {
fptr = fstr;
alloc_fstr = true;
} else {
format_clean_up(sno0, sno, finfo);
Yap_Error(TYPE_ERROR_TEXT, tail, "format/2");
Yap_ThrowError(TYPE_ERROR_TEXT, tail, "format/2");
return false;
}
if (IsVarTerm(args)) {
pop_text_stack(l);
format_clean_up(sno0, sno, finfo);
Yap_Error(INSTANTIATION_ERROR, args, "format/2");
Yap_ThrowError(INSTANTIATION_ERROR, args, "format/2");
return FALSE;
}
while (IsApplTerm(args) && FunctorOfTerm(args) == FunctorModule) {
@ -440,19 +462,19 @@ static Int doformat(volatile Term otail, volatile Term oargs,
if (IsVarTerm(fmod)) {
format_clean_up(sno0, sno, finfo);
pop_text_stack(l);
Yap_Error(INSTANTIATION_ERROR, fmod, "format/2");
Yap_ThrowError(INSTANTIATION_ERROR, fmod, "format/2");
return false;
}
if (!IsAtomTerm(fmod)) {
format_clean_up(sno0, sno, finfo);
pop_text_stack(l);
Yap_Error(TYPE_ERROR_ATOM, fmod, "format/2");
Yap_ThrowError(TYPE_ERROR_ATOM, fmod, "format/2");
return false;
}
if (IsVarTerm(args)) {
format_clean_up(sno0, sno, finfo);
pop_text_stack(l);
Yap_Error(INSTANTIATION_ERROR, args, "format/2");
Yap_ThrowError(INSTANTIATION_ERROR, args, "format/2");
return FALSE;
}
}
@ -968,7 +990,7 @@ static Int doformat(volatile Term otail, volatile Term oargs,
Term ta[2];
ta[0] = otail;
ta[1] = oargs;
Yap_Error(LOCAL_Error_TYPE,
Yap_ThrowError(LOCAL_Error_TYPE,
Yap_MkApplTerm(Yap_MkFunctor(AtomFormat, 2), 2, ta),
"arguments to format");
}
@ -1028,7 +1050,7 @@ static Term memStreamToTerm(int output_stream, Functor f, Term inp) {
} else if (f == FunctorString1) {
return Yap_CharsToString(s, enc PASS_REGS);
}
Yap_Error(DOMAIN_ERROR_FORMAT_OUTPUT, inp, NULL);
Yap_ThrowError(DOMAIN_ERROR_FORMAT_OUTPUT, inp, NULL);
return 0L;
}
@ -1088,7 +1110,7 @@ static Int with_output_to(USES_REGS1) {
bool mem_stream = false;
yhandle_t hdl = Yap_PushHandle(tin);
if (IsVarTerm(tin)) {
Yap_Error(INSTANTIATION_ERROR, tin, "with_output_to/3");
Yap_ThrowError(INSTANTIATION_ERROR, tin, "with_output_to/3");
return false;
}
if (IsApplTerm(tin) && (f = FunctorOfTerm(tin))) {
@ -1129,7 +1151,7 @@ static Int format(Term tf, Term tas, Term tout USES_REGS) {
bool mem_stream = false;
if (IsVarTerm(tout)) {
Yap_Error(INSTANTIATION_ERROR, tout, "format/3");
Yap_ThrowError(INSTANTIATION_ERROR, tout, "format/3");
return false;
}
yhandle_t hl = Yap_StartHandles(), yo = Yap_PushHandle(tout);

View File

@ -176,7 +176,7 @@ extern int Yap_peekWide(int sno);
extern int Yap_peekChar(int sno);
extern Term Yap_syntax_error(TokEntry *tokptr, int sno);
extern Term Yap_syntax_error(TokEntry *tokptr, int sno, const char *msg);
extern int console_post_process_read_char(int, StreamDesc *);
extern int console_post_process_eof(StreamDesc *);

View File

@ -95,7 +95,7 @@ static char SccsId[] = "%W% %G%";
#define SYSTEM_STAT stat
#endif
static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int start);
static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int start, bool code, const char *msg);
static void clean_vars(VarEntry *p) {
if (p == NULL)
@ -316,7 +316,7 @@ static Int scan_to_list(USES_REGS1) {
}
/**
* Syntaax Error Handler
* Syntax Error Handler
*
* @par tokptr: the sequence of tokens
* @par sno: the stream numbet
@ -324,123 +324,107 @@ static Int scan_to_list(USES_REGS1) {
* Implicit arguments:
* +
*/
static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos) {
static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool code, const char *msg) {
CACHE_REGS
Term startline, errline, endline;
Term tf[4];
Term tm;
Term *tailp = tf + 3;
CELL *Hi = HR;
Yap_MkErrorRecord( LOCAL_ActiveError, __FILE__, __FUNCTION__, __LINE__, SYNTAX_ERROR, 0, NULL);
TokEntry *tok = LOCAL_tokptr;
Int cline = tok->TokLine;
Int start_line = tok->TokLine;
Int err_line = errtok->TokLine;
Int end_line = GetCurInpLine(GLOBAL_Stream+sno);
Int startpos = tok->TokPos;
errtok = LOCAL_toktide;
Int errpos = errtok->TokPos;
UInt diff = 0;
startline = MkIntegerTerm(cline);
Yap_local.ActiveError->errorNo = SYNTAX_ERROR;
Yap_local.ActiveError->prologPredFirstLine = cline;
Yap_local.ActiveError->prologPredLastLine = cline;
endline = MkIntegerTerm(cline);
Int endpos = GetCurInpPos(GLOBAL_Stream+sno);
LOCAL_Error_TYPE = YAP_NO_ERROR;
errline = MkIntegerTerm(errtok->TokLine);
Yap_local.ActiveError->prologPredLine = errtok->TokLine;
if (!LOCAL_ErrorMessage) {
LOCAL_ErrorMessage = "syntax error";
}
tm = MkStringTerm(LOCAL_ErrorMessage);
{
char *s = malloc(strlen(LOCAL_ErrorMessage) + 1);
strcpy(s, LOCAL_ErrorMessage);
Yap_local.ActiveError->errorMsg = s;
}
if (GLOBAL_Stream[sno].status & Seekable_Stream_f) {
if (errpos && newpos >= 0) {
char o[128 + 1];
diff = errpos - startpos;
if (diff > 128) {
diff = 128;
startpos = errpos - diff;
}
Yap_local.ActiveError->errorNo = SYNTAX_ERROR;
Yap_local.ActiveError->parserFirstLine = start_line;
Yap_local.ActiveError->parserLine = err_line;
Yap_local.ActiveError->parserLastLine = end_line;
Yap_local.ActiveError->parserFirstPos = startpos;
Yap_local.ActiveError->parserPos = errpos;
Yap_local.ActiveError->parserLastPos =endpos;
Yap_local.ActiveError->parserFile =
RepAtom(AtomOfTerm((GLOBAL_Stream+sno)->user_name))->StrOfAE;
Yap_local.ActiveError->parserReadingCode = code;
#if HAVE_FTELLO
Int curpos = ftello(GLOBAL_Stream[sno].file);
fseeko(GLOBAL_Stream[sno].file, startpos, SEEK_SET);
#else
Int curpos = ftell(GLOBAL_Stream[sno].file);
fseek(GLOBAL_Stream[sno].file, startpos, SEEK_SET);
#endif
fread(o, diff, 1, GLOBAL_Stream[sno].file);
#if HAVE_FTELLO
fseeko(GLOBAL_Stream[sno].file, curpos, SEEK_SET);
#else
fseek(GLOBAL_Stream[sno].file, curpos, SEEK_SET);
#endif
o[diff] = '\0';
tf[3] = MkStringTerm(o);
}
int lvl = push_text_stack();
if (GLOBAL_Stream[sno].status & Seekable_Stream_f) {
char *o, *o2;
if (errpos <= startpos) {
o = malloc(1);
o[0] = '\0';
} else {
while (tok) {
Int sza = (errpos-startpos)+1;
o = malloc(sza);
fread(o,sza-1,1,GLOBAL_Stream[sno].file);
o[sza-1] = '\0';
if (HR > ASP - 1024) {
errline = MkIntegerTerm(0);
endline = MkIntegerTerm(0);
/* for some reason moving this earlier confuses gcc on solaris */
HR = Hi;
break;
}
if (tok->TokLine != cline) {
*tailp = MkPairTerm(TermNewLine, TermNil);
tailp = RepPair(*tailp) + 1;
cline = tok->TokLine;
}
if (tok == errtok && tok->Tok != Error_tok) {
*tailp = MkPairTerm(MkAtomTerm(AtomError), TermNil);
tailp = RepPair(*tailp) + 1;
}
Term rep = Yap_tokRep(tok);
if (tok->TokNext) {
tok = tok->TokNext;
Yap_local.ActiveError->parserTextA = o;
if (endpos <= errpos) {
o2 = malloc(1);
o2[0] = '\0';
} else {
endline = MkIntegerTerm(tok->TokLine);
tok = NULL;
break;
Int sza = (endpos-errpos)+1;
o2 = malloc(sza);
fread(o2,sza-1,1,GLOBAL_Stream[sno].file);
o2[sza-1] = '\0';
}
*tailp = MkPairTerm(rep, TermNil);
tailp = RepPair(*tailp) + 1;
Yap_local.ActiveError->parserTextB = o2;
} else {
size_t sz = 1024, total=sz, e;
char *o = malloc(1024);
char *s = o;
o[0] = '\0';
while (tok) {
if (tok->Tok == Error_tok) {
o = realloc(o, strlen(o)+1);
Yap_local.ActiveError->parserTextA= o;
o = malloc(1024);
total = sz = 1024;
tok = tok->TokNext;
continue;
}
const char *ns = Yap_tokText(tok);
e = strlen(ns);
if (ns && ns[0] && e+1 > sz-256) {
strcat(s,ns);
o += e;
sz -= e;
}
{
Term t[3];
t[0] = startline;
t[1] = errline;
t[2] = endline;
tf[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomBetween, 3), 3, t);
if (tok->TokNext && tok->TokNext->TokLine > tok->TokLine) {
strcat(s,"\n")
;sz--;
}
tok = tok->TokNext;
}
o = realloc(o, strlen(o)+1);
Yap_local.ActiveError->parserTextA= o;
}
/* 0: strat, error, end line */
/*2 msg */
/* 1: file */
tf[1] = Yap_StreamUserName(sno);
tf[2] = MkIntegerTerm(LOCAL_ActiveError->prologParserPos);
if (!msg)
msg = "unspecified";
Yap_local.ActiveError->culprit =
Yap_local.ActiveError->errorMsg = (char*)msg;
Yap_local.ActiveError->errorMsgLen = strlen(msg);
clean_vars(LOCAL_VarTable);
clean_vars(LOCAL_AnonVarTable);
Term terr = Yap_MkApplTerm(FunctorInfo4, 4, tf);
Term tn[2];
tn[0] = Yap_MkApplTerm(FunctorShortSyntaxError, 1, &tm);
tn[1] = terr;
terr = Yap_MkApplTerm(FunctorError, 2, tn);
#if DEBUG
if (Yap_ExecutionMode == YAP_BOOT_MODE) {
fprintf(stderr, "SYNTAX ERROR while booting: ");
fe
}
#endif
return terr;
pop_text_stack(lvl);
return Yap_MkFullError();
}
Term Yap_syntax_error(TokEntry *errtok, int sno) {
return syntax_error(errtok, sno, CurrentModule, -1);
Term Yap_syntax_error(TokEntry *errtok, int sno, const char *msg) {
return syntax_error(errtok, sno, CurrentModule, -1, false, msg);
}
typedef struct FEnv {
@ -457,6 +441,7 @@ typedef struct FEnv {
encoding_t enc; /// encoding of the stream being read
Term tcomms; /// Access to comments
Term cmod; /// Access to comments
char *msg; /// Error Messagge
} FEnv;
typedef struct renv {
@ -555,6 +540,7 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) {
} else {
re->prio = LOCAL_default_priority;
}
fe->msg = NULL;
return args;
}
@ -795,17 +781,19 @@ static parser_state_t scanEOF(FEnv *fe, int inp_stream) {
// check for an user abort
if (tokstart != NULL && tokstart->Tok != Ord(eot_tok)) {
/* we got the end of file from an abort */
if (LOCAL_ErrorMessage && !strcmp(LOCAL_ErrorMessage, "Abort")) {
if (fe->msg && !strcmp(fe->msg, "Abort")) {
fe->t = 0L;
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable);
return YAP_PARSING_FINISHED;
}
// a :- <eof>
if (GLOBAL_Stream[inp_stream].status & Past_Eof_Stream_f)
if (GLOBAL_Stream[inp_stream].status & Past_Eof_Stream_f) {
fe->msg = "parsing stopped at a end-of-file";
return YAP_PARSING_ERROR;
}
/* we need to force the next read to also give end of file.*/
GLOBAL_Stream[inp_stream].status |= Push_Eof_Stream_f;
LOCAL_ErrorMessage = "end of file found before end of term";
fe->msg = "end of file found before end of term";
return YAP_PARSING;
} else {
// <eof>
@ -838,7 +826,6 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
LOCAL_SourceFileName = GLOBAL_Stream[inp_stream].name;
LOCAL_eot_before_eof = false;
fe->tpos = StreamPosition(inp_stream);
fe->old_H = HR;
fe->reading_clause = clause;
if (clause) {
fe->args = setClauseReadEnv(opts, fe, re, inp_stream);
@ -890,7 +877,7 @@ static parser_state_t scan(REnv *re, FEnv *fe, int sno) {
return YAP_PARSING;
}
if (LOCAL_tokptr->Tok == eot_tok && LOCAL_tokptr->TokInfo == TermNl) {
LOCAL_Error_TYPE = SYNTAX_ERROR;
LOCAL_ErrorMessage = ". is end-of-term?";
return YAP_PARSING_ERROR;
}
return scanEOF(fe, sno);
@ -950,21 +937,24 @@ static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) {
/* just fail */
LOCAL_Error_TYPE = YAP_NO_ERROR;
return YAP_PARSING_FINISHED;
} else {
}
Term t = syntax_error(fe->toklast, inp_stream, fe->cmod, re->cpos, fe->reading_clause, fe->msg);
if (ParserErrorStyle == TermException) {
if (LOCAL_RestartEnv && !LOCAL_delay) {
Yap_RestartYap(5);
}
Yap_exit(5);
}
if (re->seekable) {
re->cpos = GLOBAL_Stream[inp_stream].charcount;
}
Term t = syntax_error(fe->toklast, inp_stream, fe->cmod, re->cpos);
if (ParserErrorStyle == TermError) {
LOCAL_ActiveError->errorRawTerm = Yap_SaveTerm(t);
LOCAL_Error_TYPE = SYNTAX_ERROR;
// dec-10
} else if (Yap_PrintWarning(t)) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
LOCAL_Error_TYPE = WARNING_SYNTAX_ERROR;
t = Yap_MkFullError();
Yap_PrintWarning(t);
LOCAL_Error_TYPE = YAPC_NO_ERROR;
if (ParserErrorStyle == TermDec10) {
return YAP_SCANNING;
}
}
return YAP_PARSING_FINISHED;
}
@ -1165,6 +1155,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re, int sno) {
re->cpos = GLOBAL_Stream[sno].charcount;
}
re->prio = LOCAL_default_priority;
fe->msg = NULL;
return args;
}

View File

@ -695,7 +695,7 @@ db_files(Fs) :-
'$csult'(Fs, _M) :-
'$skip_list'(_, Fs ,L),
vz L \== [],
L \== [],
!,
user:dot_qualified_goal(Fs).
'$csult'(Fs, M) :-

View File

@ -197,8 +197,14 @@ compose_message( halt, _Level) --> !,
[ 'YAP execution halted.'-[] ].
% syntax error.
compose_message(error(warning(syntax_error,Info), Exc), Level) -->
!,
compose_message(error(syntax_error(Info), Exc), Level).
compose_message(error(E, Exc), Level) -->
{ '$show_consult_level'(LC) },
{
% start_low_level_trace,
'$show_consult_level'(LC)
},
location(error(E, Exc), Level, LC),
main_message(error(E,Exc) , Level, LC ),
c_goal( error(E, Exc), Level ),
@ -249,8 +255,15 @@ compose_message(Throw, _Level) -->
!,
[ 'UNHANDLED EXCEPTION - message ~w unknown' - [Throw] ].
location(error(syntax_error(_),info(between(_,LN,_), FileName, _ChrPos, _Err)), _ , _) -->
location(error(syntax_error(_),Info), _Level , LC) -->
{ '$error_descriptor'(Info, Desc) },
{ query_exception(parserReadingCode, Desc, true) },
{LC > 0},
!,
{
query_exception(parserFile, Desc, FileName),
query_exception(parserLine, Desc, LN)
},
[ '~a:~d:~d: ' - [FileName,LN,0] ] .
location(style_check(A,LN,FileName,B ), Level , LC) -->
!,
@ -289,21 +302,17 @@ simplify_pred(F, F).
%message(loaded(Past,AbsoluteFileName,user,Msec,Bytes), Prefix, Suffix) :- !,
main_message(error(Msg,In), _, _) --> {var(Msg)}, !,
[ 'Uninstantiated message ~w~n.' - [error(Msg,In)], nl ].
main_message( error(syntax_error(Msg),info(between(L0,LM,LF),_Stream, _Pos, Term)), Level, LC ) -->
main_message( error(syntax_error(Msg),Info), Level, _LC ) -->
!,
{
'$error_descriptor'(Info, Desc),
query_exception(parserTextA, Desc, J),
query_exception(parserTextB, Desc, T),
query_exception(parserLine, Desc, L)
},
[' ~a: syntax error ~s' - [Level,Msg]],
[nl],
( syntax_error_term( between(L0,LM,LF), Term, LC )
->
[]
;
[' ~a: failed_processing syntax error term ~q' - [Level,Term]],
[nl]
).
main_message( error(syntax_error(Msg), _Info), Level, _LC ) -->
!,
[' ~a: syntax error ~s' - [Level,Msg]],
[nl].
[' ~s <<== at line ~d == ~s !' - [J,L,T], nl ].
main_message(style_check(singleton(SVs),_Pos,_File,P), _Level, _LC) -->
!,
% {writeln(ci)},
@ -370,6 +379,7 @@ display_consulting( F, Level, _, LC) -->
display_consulting(_F, _, _, _LC) -->
[].
c_goal( error(syntax_error(_),Info), _) --> !.
c_goal( error(_,Info), _) -->
{ '$error_descriptor'(Info, Desc) },
({ query_exception(errorGoal, Desc, Call),
@ -711,7 +721,7 @@ syntax_error_token(var(_,S), _, _LC) --> !,
syntax_error_token(string(S), _, _LC) --> !,
[ '`~s`' - [S] ].
syntax_error_token(error, L, _LC) --> !,
[ ' <<<< at line %d' - [L] ].
[ ' <<<< at line ~d >>>> ' - [L] ].
syntax_error_token('EOT',_, _LC) --> !,
[ '.' - [], nl ].
syntax_error_token('(',_, _LC) --> !,