indent + EOF work in progress

This commit is contained in:
Vítor Santos Costa 2015-07-06 11:49:56 +01:00
parent f5b50a4179
commit 4c56769210
1 changed files with 1218 additions and 1198 deletions

View File

@ -502,7 +502,7 @@ static char chtype0[NUMBER_OF_CHARS + 1] = {
BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS,
BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS,
/*   ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ */ /* ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ */
BS, SY, SY, SY, SY, SY, SY, SY, SY, BS, SY, SY, SY, SY, SY, SY, SY, SY,
SY, LC, SY, SY, SY, SY, SY, SY, LC, SY, SY, SY, SY, SY,
@ -1174,6 +1174,14 @@ static void close_comment(USES_REGS1) {
LOCAL_CommentsBuffLim = 0; LOCAL_CommentsBuffLim = 0;
} }
// mark that we reached EOF,
// next token will be end_of_file)
static void
mark_eof( struct stream_desc * inp_stream )
{
inp_stream->status |= Push_Eof_Stream_f;
}
static wchar_t *ch_to_wide(char *base, char *charp) { static wchar_t *ch_to_wide(char *base, char *charp) {
CACHE_REGS CACHE_REGS
int n = charp - base, i; int n = charp - base, i;
@ -1314,6 +1322,7 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
goto restart; goto restart;
} else { } else {
t->Tok = Ord(kind = eot_tok); t->Tok = Ord(kind = eot_tok);
mark_eof(inp_stream);
} }
break; break;
@ -1532,6 +1541,7 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
} }
} else if (chtype(ch) == EF && ch <= MAX_ISO_LATIN1) { } else if (chtype(ch) == EF && ch <= MAX_ISO_LATIN1) {
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage); Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
mark_eof(inp_stream);
t->Tok = Ord(kind = eot_tok); t->Tok = Ord(kind = eot_tok);
break; break;
} else { } else {
@ -1594,13 +1604,17 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
return l; return l;
} }
if (wcharp) { if (wcharp) {
utf8_wcscpy(mp, (const wchar_t *)TokImage); wcscpy((wchar_t *)mp, (wchar_t *)TokImage);
} else { } else {
strcpy(mp, TokImage); strcpy(mp, TokImage);
} }
t->TokInfo = Unsigned(mp); t->TokInfo = Unsigned(mp);
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage); Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
t->Tok = Ord(kind = StringTerm_tok); if (wcharp) {
t->Tok = Ord(kind = WBQString_tok);
} else {
t->Tok = Ord(kind = BQString_tok);
}
} else { } else {
if (wcharp) { if (wcharp) {
t->TokInfo = Unsigned(Yap_LookupWideAtom((wchar_t *)TokImage)); t->TokInfo = Unsigned(Yap_LookupWideAtom((wchar_t *)TokImage));
@ -1618,12 +1632,12 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage); Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
t->Tok = Ord(kind = Name_tok); t->Tok = Ord(kind = Name_tok);
if (ch == '(') if (ch == '(')
solo_flag = FALSE; solo_flag = false;
} }
break; break;
case SY: case SY:
if (ch == '`' && trueGlobalPrologFlag(BACKQUOTED_STRING_FLAG)) if (ch == '`')
goto quoted_string; goto quoted_string;
och = ch; och = ch;
ch = getchr(inp_stream); ch = getchr(inp_stream);
@ -1650,6 +1664,7 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
} }
if (chtype(ch) == EF) { if (chtype(ch) == EF) {
t->Tok = Ord(kind = eot_tok); t->Tok = Ord(kind = eot_tok);
break;
} else { } else {
/* leave comments */ /* leave comments */
ch = getchr(inp_stream); ch = getchr(inp_stream);
@ -1672,6 +1687,9 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF) while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF)
; ;
t->Tok = Ord(kind = eot_tok); t->Tok = Ord(kind = eot_tok);
if (chtype(chtype(ch)) == EF)
mark_eof(inp_stream);
break;
} else { } else {
Atom ae; Atom ae;
TokImage = ((AtomEntry *)(Yap_PreAllocCodeSpace()))->StrOfAE; TokImage = ((AtomEntry *)(Yap_PreAllocCodeSpace()))->StrOfAE;
@ -1847,6 +1865,7 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
} }
} else if (chtype(ch) == EF) { } else if (chtype(ch) == EF) {
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage); Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
mark_eof(inp_stream);
t->Tok = Ord(kind = eot_tok); t->Tok = Ord(kind = eot_tok);
break; break;
} else { } else {
@ -1899,6 +1918,7 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
t->Tok = Ord(kind = Ponctuation_tok); t->Tok = Ord(kind = Ponctuation_tok);
break; break;
case EF: case EF:
mark_eof(inp_stream);
t->Tok = Ord(kind = eot_tok); t->Tok = Ord(kind = eot_tok);
break; break;