don't consume char after '.', do peek instead.

early errors should leave early.
This commit is contained in:
Vítor Santos Costa 2016-02-14 04:11:55 +00:00
parent df0b3d3a0d
commit 92cb3e34eb

View File

@ -563,9 +563,7 @@ typedef struct scanner_extra_alloc {
void *filler;
} ScannerExtraBlock;
static TokEntry *
CodeSpaceError(TokEntry *t, TokEntry *p, TokEntry *l)
{
static TokEntry *CodeSpaceError(TokEntry *t, TokEntry *p, TokEntry *l) {
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
LOCAL_ErrorMessage = "Code Space Overflow";
if (t) {
@ -574,11 +572,9 @@ CodeSpaceError(TokEntry *t, TokEntry *p, TokEntry *l)
}
/* serious error now */
return l;
}
}
static TokEntry *
TrailSpaceError(TokEntry *t, TokEntry *l)
{
static TokEntry *TrailSpaceError(TokEntry *t, TokEntry *l) {
LOCAL_ErrorMessage = "Trail Overflow";
LOCAL_Error_TYPE = RESOURCE_ERROR_TRAIL;
if (t) {
@ -588,9 +584,7 @@ TrailSpaceError(TokEntry *t, TokEntry *l)
return l;
}
static TokEntry *
AuxSpaceError(TokEntry *p, TokEntry *l, const char *msg)
{
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;
@ -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;
@ -1669,7 +1663,8 @@ 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) {
@ -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;
@ -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;
@ -2021,10 +2034,10 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
t->TokInfo = TermEof;
return l;
default:
{
default: {
char err[1024];
snprintf( err, 1023, "\n++++ token: unrecognised char %c (%d), type %c\n", ch, ch, chtype(ch) );
snprintf(err, 1023, "\n++++ token: unrecognised char %c (%d), type %c\n",
ch, ch, chtype(ch));
#if DEBUG
fprintf(stderr, "%s", err);
#endif