indent + EOF work in progress
This commit is contained in:
parent
f5b50a4179
commit
4c56769210
64
C/scanner.c
64
C/scanner.c
@ -453,7 +453,7 @@ Yap_setCurrentSourceLocation( struct stream_desc *s )
|
|||||||
else
|
else
|
||||||
LOCAL_SourceFileName = s->name;
|
LOCAL_SourceFileName = s->name;
|
||||||
LOCAL_SourceFileLineno = s->linecount;
|
LOCAL_SourceFileLineno = s->linecount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* token table with some help from Richard O'Keefe's PD scanner */
|
/* token table with some help from Richard O'Keefe's PD scanner */
|
||||||
static char chtype0[NUMBER_OF_CHARS + 1] = {
|
static char chtype0[NUMBER_OF_CHARS + 1] = {
|
||||||
@ -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,
|
||||||
|
|
||||||
@ -514,27 +514,27 @@ static char chtype0[NUMBER_OF_CHARS + 1] = {
|
|||||||
UC, UC, UC, UC, UC, UC, UC, UC, UC,
|
UC, UC, UC, UC, UC, UC, UC, UC, UC,
|
||||||
UC, UC, UC, UC, UC, UC, UC,
|
UC, UC, UC, UC, UC, UC, UC,
|
||||||
|
|
||||||
/* Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß */
|
/* Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß */
|
||||||
#ifdef vms
|
#ifdef vms
|
||||||
UC, UC, UC, UC, UC, UC, UC, UC, UC,
|
UC, UC, UC, UC, UC, UC, UC, UC, UC,
|
||||||
UC, UC, UC, UC, UC, UC, LC,
|
UC, UC, UC, UC, UC, UC, LC,
|
||||||
#else
|
#else
|
||||||
UC, UC, UC, UC, UC, UC, UC, SY, UC,
|
UC, UC, UC, UC, UC, UC, UC, SY, UC,
|
||||||
UC, UC, UC, UC, UC, UC, LC,
|
UC, UC, UC, UC, UC, UC, LC,
|
||||||
#endif
|
#endif
|
||||||
/* à á â ã ä å æ ç è é ê ë ì í î ï */
|
/* à á â ã ä å æ ç è é ê ë ì í î ï */
|
||||||
LC, LC, LC, LC, LC, LC, LC, LC, LC,
|
LC, LC, LC, LC, LC, LC, LC, LC, LC,
|
||||||
LC, LC, LC, LC, LC, LC, LC,
|
LC, LC, LC, LC, LC, LC, LC,
|
||||||
|
|
||||||
/* ð ñ ò ó ô õ ö ÷ ø ù ú û ü cannot write the last
|
/* ð ñ ò ó ô õ ö ÷ ø ù ú û ü cannot write the last
|
||||||
* three because of lcc */
|
* three because of lcc */
|
||||||
#ifdef vms
|
#ifdef vms
|
||||||
LC, LC, LC, LC, LC, LC, LC, LC, LC,
|
LC, LC, LC, LC, LC, LC, LC, LC, LC,
|
||||||
LC, LC, LC, LC, LC, LC, LC
|
LC, LC, LC, LC, LC, LC, LC
|
||||||
#else
|
#else
|
||||||
LC, LC, LC, LC, LC, LC, LC, SY, LC,
|
LC, LC, LC, LC, LC, LC, LC, SY, LC,
|
||||||
LC, LC, LC, LC, LC, LC, LC
|
LC, LC, LC, LC, LC, LC, LC
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
char *Yap_chtype = chtype0 + 1;
|
char *Yap_chtype = chtype0 + 1;
|
||||||
@ -680,7 +680,7 @@ static int send_error_message(char s[]) {
|
|||||||
static wchar_t read_quoted_char(int *scan_nextp, struct stream_desc* inp_stream) {
|
static wchar_t read_quoted_char(int *scan_nextp, struct stream_desc* inp_stream) {
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
/* escape sequence */
|
/* escape sequence */
|
||||||
do_switch:
|
do_switch:
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(inp_stream);
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
@ -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;
|
||||||
@ -1213,7 +1221,7 @@ static wchar_t *ch_to_wide(char *base, char *charp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define add_ch_to_utf8_buff(ch) \
|
#define add_ch_to_utf8_buff(ch) \
|
||||||
{ \
|
{ \
|
||||||
if ((ch & 0xff) == ch) { \
|
if ((ch & 0xff) == ch) { \
|
||||||
*charp++ = ch; \
|
*charp++ = ch; \
|
||||||
} else { \
|
} else { \
|
||||||
@ -1269,7 +1277,7 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
|
|||||||
else
|
else
|
||||||
p->TokNext = t;
|
p->TokNext = t;
|
||||||
p = t;
|
p = t;
|
||||||
restart:
|
restart:
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(inp_stream);
|
||||||
}
|
}
|
||||||
@ -1281,7 +1289,7 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
|
|||||||
if (store_comments) {
|
if (store_comments) {
|
||||||
CHECK_SPACE();
|
CHECK_SPACE();
|
||||||
open_comment(ch, inp_stream PASS_REGS);
|
open_comment(ch, inp_stream PASS_REGS);
|
||||||
continue_comment:
|
continue_comment:
|
||||||
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF) {
|
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF) {
|
||||||
CHECK_SPACE();
|
CHECK_SPACE();
|
||||||
extend_comment(ch PASS_REGS);
|
extend_comment(ch PASS_REGS);
|
||||||
@ -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;
|
||||||
|
|
||||||
@ -1322,7 +1331,7 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
|
|||||||
case LC:
|
case LC:
|
||||||
och = ch;
|
och = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(inp_stream);
|
||||||
scan_name:
|
scan_name:
|
||||||
TokImage = ((AtomEntry *)(Yap_PreAllocCodeSpace()))->StrOfAE;
|
TokImage = ((AtomEntry *)(Yap_PreAllocCodeSpace()))->StrOfAE;
|
||||||
charp = TokImage;
|
charp = TokImage;
|
||||||
wcharp = NULL;
|
wcharp = NULL;
|
||||||
@ -1330,7 +1339,7 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
|
|||||||
add_ch_to_buff(och);
|
add_ch_to_buff(och);
|
||||||
for (; chtype(ch) <= NU; ch = getchr(inp_stream)) {
|
for (; chtype(ch) <= NU; ch = getchr(inp_stream)) {
|
||||||
if (charp == (char *)AuxSp - 1024) {
|
if (charp == (char *)AuxSp - 1024) {
|
||||||
huge_var_error:
|
huge_var_error:
|
||||||
/* huge atom or variable, we are in trouble */
|
/* huge atom or variable, we are in trouble */
|
||||||
LOCAL_ErrorMessage = "Code Space Overflow due to huge atom";
|
LOCAL_ErrorMessage = "Code Space Overflow due to huge atom";
|
||||||
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
|
LOCAL_Error_TYPE = OUT_OF_AUXSPACE_ERROR;
|
||||||
@ -1495,7 +1504,7 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
|
|||||||
|
|
||||||
case QT:
|
case QT:
|
||||||
case DC:
|
case DC:
|
||||||
quoted_string:
|
quoted_string:
|
||||||
TokImage = ((AtomEntry *)(Yap_PreAllocCodeSpace()))->StrOfAE;
|
TokImage = ((AtomEntry *)(Yap_PreAllocCodeSpace()))->StrOfAE;
|
||||||
charp = TokImage;
|
charp = TokImage;
|
||||||
quote = ch;
|
quote = ch;
|
||||||
@ -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);
|
||||||
@ -1665,13 +1680,16 @@ TokEntry *Yap_tokenizer( struct stream_desc *inp_stream,
|
|||||||
}
|
}
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
enter_symbol:
|
enter_symbol:
|
||||||
if (och == '.' &&
|
if (och == '.' &&
|
||||||
(chtype(ch) == BS || chtype(ch) == EF || chtype(ch) == CC)) {
|
(chtype(ch) == BS || chtype(ch) == EF || chtype(ch) == CC)) {
|
||||||
if (chtype(ch) == CC)
|
if (chtype(ch) == CC)
|
||||||
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;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user