don't consume char after '.', do peek instead.
early errors should leave early.
This commit is contained in:
parent
df0b3d3a0d
commit
92cb3e34eb
145
C/scanner.c
145
C/scanner.c
@ -563,44 +563,38 @@ typedef struct scanner_extra_alloc {
|
||||
void *filler;
|
||||
} ScannerExtraBlock;
|
||||
|
||||
static TokEntry *
|
||||
CodeSpaceError(TokEntry *t, TokEntry *p, TokEntry *l)
|
||||
{
|
||||
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
|
||||
LOCAL_ErrorMessage = "Code Space Overflow";
|
||||
if (t) {
|
||||
t->Tok = eot_tok;
|
||||
t->TokInfo = TermOutOfHeapError;
|
||||
}
|
||||
/* serious error now */
|
||||
return l;
|
||||
}
|
||||
|
||||
static TokEntry *
|
||||
TrailSpaceError(TokEntry *t, TokEntry *l)
|
||||
{
|
||||
LOCAL_ErrorMessage = "Trail Overflow";
|
||||
LOCAL_Error_TYPE = RESOURCE_ERROR_TRAIL;
|
||||
if (t) {
|
||||
t->Tok = eot_tok;
|
||||
t->TokInfo = TermOutOfTrailError;
|
||||
}
|
||||
return l;
|
||||
static TokEntry *CodeSpaceError(TokEntry *t, TokEntry *p, TokEntry *l) {
|
||||
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
|
||||
LOCAL_ErrorMessage = "Code Space Overflow";
|
||||
if (t) {
|
||||
t->Tok = eot_tok;
|
||||
t->TokInfo = TermOutOfHeapError;
|
||||
}
|
||||
/* serious error now */
|
||||
return l;
|
||||
}
|
||||
|
||||
static TokEntry *
|
||||
AuxSpaceError(TokEntry *p, TokEntry *l, const char *msg)
|
||||
{
|
||||
/* huge atom or variable, we are in trouble */
|
||||
LOCAL_ErrorMessage = (char *)msg;
|
||||
LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK;
|
||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||
if (p) {
|
||||
p->Tok = eot_tok;
|
||||
p->TokInfo = TermOutOfAuxspaceError;
|
||||
}
|
||||
/* serious error now */
|
||||
return l;
|
||||
static TokEntry *TrailSpaceError(TokEntry *t, TokEntry *l) {
|
||||
LOCAL_ErrorMessage = "Trail Overflow";
|
||||
LOCAL_Error_TYPE = RESOURCE_ERROR_TRAIL;
|
||||
if (t) {
|
||||
t->Tok = eot_tok;
|
||||
t->TokInfo = TermOutOfTrailError;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
static TokEntry *AuxSpaceError(TokEntry *p, TokEntry *l, const char *msg) {
|
||||
/* huge atom or variable, we are in trouble */
|
||||
LOCAL_ErrorMessage = (char *)msg;
|
||||
LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK;
|
||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||
if (p) {
|
||||
p->Tok = eot_tok;
|
||||
p->TokInfo = TermOutOfAuxspaceError;
|
||||
}
|
||||
/* serious error now */
|
||||
return l;
|
||||
}
|
||||
|
||||
static void InitScannerMemory(void) {
|
||||
@ -1221,10 +1215,10 @@ Term Yap_scan_num(StreamDesc *inp) {
|
||||
LOCAL_ErrorMessage = "Stack Overflow"; \
|
||||
LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \
|
||||
LOCAL_Error_Size = 0L; \
|
||||
if (p) { \
|
||||
if (p) { \
|
||||
p->Tok = Ord(kind = eot_tok); \
|
||||
p->TokInfo = TermOutOfStackError; \
|
||||
} \
|
||||
} \
|
||||
/* serious error now */ \
|
||||
return l; \
|
||||
}
|
||||
@ -1403,7 +1397,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
LOCAL_StartLineCount = inp_stream->linecount;
|
||||
LOCAL_StartLinePos = inp_stream->linepos;
|
||||
do {
|
||||
wchar_t och;
|
||||
wchar_t och, pch;
|
||||
int quote, isvar;
|
||||
char *charp, *mp;
|
||||
unsigned int len;
|
||||
@ -1506,7 +1500,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
ae = Yap_LookupAtom(TokImage);
|
||||
}
|
||||
if (ae == NIL) {
|
||||
return CodeSpaceError(t, p, l);
|
||||
return CodeSpaceError(t, p, l);
|
||||
}
|
||||
t->TokInfo = Unsigned(ae);
|
||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||
@ -1531,8 +1525,8 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
|
||||
cherr = 0;
|
||||
if (!(ptr = AllocScannerMemory(4096))) {
|
||||
return TrailSpaceError(t, l);
|
||||
}
|
||||
return TrailSpaceError(t, l);
|
||||
}
|
||||
CHECK_SPACE();
|
||||
if ((t->TokInfo = get_num(&cha, &cherr, inp_stream, ptr, 4096, 1)) ==
|
||||
0L) {
|
||||
@ -1551,7 +1545,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
t->TokPos = GetCurInpPos(inp_stream);
|
||||
e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||
if (e == NULL) {
|
||||
return TrailSpaceError(p, l);
|
||||
return TrailSpaceError(p, l);
|
||||
|
||||
} else {
|
||||
e->TokNext = NULL;
|
||||
@ -1576,7 +1570,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
t->TokPos = GetCurInpPos(inp_stream);
|
||||
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||
if (e2 == NULL) {
|
||||
return TrailSpaceError(p, l);
|
||||
return TrailSpaceError(p, l);
|
||||
} else {
|
||||
e2->TokNext = NULL;
|
||||
}
|
||||
@ -1602,7 +1596,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
t->TokPos = GetCurInpPos(inp_stream);
|
||||
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||
if (e2 == NULL) {
|
||||
return TrailSpaceError(p, l);
|
||||
return TrailSpaceError(p, l);
|
||||
} else {
|
||||
e2->TokNext = NULL;
|
||||
}
|
||||
@ -1669,8 +1663,9 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
++len;
|
||||
if (charp > (char *)AuxSp - 1024) {
|
||||
/* Not enough space to read in the string. */
|
||||
return AuxSpaceError(t, l, "not enough space to read in string or quoted atom");
|
||||
}
|
||||
return AuxSpaceError(
|
||||
t, l, "not enough space to read in string or quoted atom");
|
||||
}
|
||||
}
|
||||
if (wcharp) {
|
||||
*wcharp = '\0';
|
||||
@ -1718,8 +1713,8 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
t->TokInfo = Unsigned(Yap_LookupAtom(TokImage));
|
||||
}
|
||||
if (!(t->TokInfo)) {
|
||||
return CodeSpaceError(t, p, l);
|
||||
}
|
||||
return CodeSpaceError(t, p, l);
|
||||
}
|
||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||
t->Tok = Ord(kind = Name_tok);
|
||||
if (ch == '(')
|
||||
@ -1730,12 +1725,29 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
case BS:
|
||||
if (ch == '\0') {
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
if (chtype(pch) == EF) {
|
||||
mark_eof(inp_stream);
|
||||
t->TokInfo = TermEof;
|
||||
} else {
|
||||
t->TokInfo = TermNewLine;
|
||||
}
|
||||
t->TokInfo = TermEof;
|
||||
return l;
|
||||
} else
|
||||
ch = getchr(inp_stream);
|
||||
break;
|
||||
case SY:
|
||||
if (ch == '.' && (pch = Yap_peek(inp_stream - GLOBAL_Stream)) &&
|
||||
(chtype(pch) == BS || chtype(pch) == EF || pch == '%')) {
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
if (chtype(ch) == EF) {
|
||||
mark_eof(inp_stream);
|
||||
t->TokInfo = TermEof;
|
||||
} else {
|
||||
t->TokInfo = TermNewLine;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
if (ch == '`')
|
||||
goto quoted_string;
|
||||
och = ch;
|
||||
@ -1747,7 +1759,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
mark_eof(inp_stream);
|
||||
t->TokInfo = TermEof;
|
||||
} else {
|
||||
t->TokInfo = TermNewLine;
|
||||
t->TokInfo = TermNewLine;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
@ -1798,9 +1810,9 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
if (chtype(ch) == EF) {
|
||||
mark_eof(inp_stream);
|
||||
t->TokInfo = TermEof;
|
||||
} else {
|
||||
} else {
|
||||
t->TokInfo = TermNl;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
} else {
|
||||
Atom ae;
|
||||
@ -1822,12 +1834,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
ae = Yap_LookupAtom(TokImage);
|
||||
}
|
||||
if (ae == NIL) {
|
||||
return CodeSpaceError(t, p, l);
|
||||
return CodeSpaceError(t, p, l);
|
||||
}
|
||||
t->TokInfo = Unsigned(ae);
|
||||
if (t->TokInfo == (CELL)NIL) {
|
||||
return CodeSpaceError(t, p, l);
|
||||
}
|
||||
return CodeSpaceError(t, p, l);
|
||||
}
|
||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||
t->Tok = Ord(kind = Name_tok);
|
||||
if (ch == '(')
|
||||
@ -1891,7 +1903,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
LOCAL_ErrorMessage = "quasi quote in quasi quote";
|
||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
t->TokInfo = TermOutOfHeapError;
|
||||
t->TokInfo = TermOutOfHeapError;
|
||||
free(qq);
|
||||
return l;
|
||||
} else {
|
||||
@ -1982,7 +1994,8 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
}
|
||||
if (charp > (char *)AuxSp - 1024) {
|
||||
/* Not enough space to read in the string. */
|
||||
return AuxSpaceError(t, l, "not enough space to read in string or quoted atom");
|
||||
return AuxSpaceError(
|
||||
t, l, "not enough space to read in string or quoted atom");
|
||||
}
|
||||
}
|
||||
len = charp - TokImage;
|
||||
@ -2006,7 +2019,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
qq->end.linepos = inp_stream->linepos - 1;
|
||||
qq->end.charno = inp_stream->charcount - 1;
|
||||
if (!(t->TokInfo)) {
|
||||
return CodeSpaceError(t, p, l);
|
||||
return CodeSpaceError(t, p, l);
|
||||
}
|
||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||
solo_flag = FALSE;
|
||||
@ -2021,14 +2034,14 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
t->TokInfo = TermEof;
|
||||
return l;
|
||||
|
||||
default:
|
||||
{
|
||||
char err[1024];
|
||||
snprintf( err, 1023, "\n++++ token: unrecognised char %c (%d), type %c\n", ch, ch, chtype(ch) );
|
||||
default: {
|
||||
char err[1024];
|
||||
snprintf(err, 1023, "\n++++ token: unrecognised char %c (%d), type %c\n",
|
||||
ch, ch, chtype(ch));
|
||||
#if DEBUG
|
||||
fprintf(stderr, "%s", err);
|
||||
fprintf(stderr, "%s", err);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
t->Tok = Ord(kind = eot_tok);
|
||||
t->TokInfo = TermEof;
|
||||
}
|
||||
@ -2040,8 +2053,8 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
||||
/* insert an error token to inform the system of what happened */
|
||||
TokEntry *e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||
if (e == NULL) {
|
||||
return TrailSpaceError(p, l);
|
||||
}
|
||||
return TrailSpaceError(p, l);
|
||||
}
|
||||
p->TokNext = e;
|
||||
e->Tok = Error_tok;
|
||||
e->TokInfo = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
|
||||
|
Reference in New Issue
Block a user