fixed a tokenization bug in getting a empty string literal.

allowed a zero-length symbol to be created
This commit is contained in:
hyunghwan.chung 2017-02-19 15:45:51 +00:00
parent 93e776a9d8
commit 8442968f9c
2 changed files with 32 additions and 29 deletions

View File

@ -1238,30 +1238,42 @@ static int get_strlit (moo_t* moo)
* normal-character := character-except-single-quote * normal-character := character-except-single-quote
*/ */
moo_ooci_t c = moo->c->lxc.c; moo_ooci_t oc, c;
SET_TOKEN_TYPE (moo, MOO_IOTOK_STRLIT);
do oc = moo->c->lxc.c; /* opening quote */
SET_TOKEN_TYPE (moo, MOO_IOTOK_STRLIT);
GET_CHAR_TO (moo, c);
if (c != oc)
{ {
do do
{ {
ADD_TOKEN_CHAR (moo, c); do
GET_CHAR_TO (moo, c);
if (c == MOO_UCI_EOF)
{ {
/* string not closed */ in_strlit:
set_syntax_error (moo, MOO_SYNERR_STRNC, TOKEN_LOC(moo) /*&moo->c->lxc.l*/, MOO_NULL); ADD_TOKEN_CHAR (moo, c);
return -1; GET_CHAR_TO (moo, c);
}
}
while (c != '\'');
/* 'c' must be a single quote at this point*/ if (c == MOO_UCI_EOF)
{
/* string not closed */
set_syntax_error (moo, MOO_SYNERR_STRNC, TOKEN_LOC(moo) /*&moo->c->lxc.l*/, MOO_NULL);
return -1;
}
}
while (c != oc);
/* 'c' must be a single quote at this point*/
GET_CHAR_TO (moo, c);
}
while (c == oc); /* if the next character is a single quote, it becomes a literal single quote character. */
}
else
{
GET_CHAR_TO (moo, c); GET_CHAR_TO (moo, c);
} if (c == oc) goto in_strlit;
while (c == '\''); /* if the next character is a single quote, }
it becomes a literal single quote character. */
unget_char (moo, &moo->c->lxc); unget_char (moo, &moo->c->lxc);
return 0; return 0;
@ -1509,7 +1521,6 @@ retry:
break; break;
case '\'': /* string literal */ case '\'': /* string literal */
GET_CHAR (moo);
if (get_strlit(moo) <= -1) return -1; if (get_strlit(moo) <= -1) return -1;
break; break;
@ -1612,9 +1623,8 @@ retry:
case '\'': case '\'':
/* quoted symbol literal */ /* quoted symbol literal */
GET_CHAR (moo); if (get_strlit(moo) <= -1) return -1; /* reuse the string literal tokenizer */
if (get_strlit(moo) <= -1) return -1; SET_TOKEN_TYPE (moo, MOO_IOTOK_SYMLIT); /* change the symbol type to symbol */
SET_TOKEN_TYPE (moo, MOO_IOTOK_SYMLIT);
break; break;
default: default:

View File

@ -88,14 +88,6 @@ static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow
moo_oow_t index; moo_oow_t index;
moo_oop_char_t symbol; moo_oop_char_t symbol;
MOO_ASSERT (moo, len > 0);
if (len <= 0)
{
/* i don't allow an empty symbol name */
moo->errnum = MOO_EINVAL;
return MOO_NULL;
}
MOO_ASSERT (moo, MOO_CLASSOF(moo,moo->symtab->bucket) == moo->_array); MOO_ASSERT (moo, MOO_CLASSOF(moo,moo->symtab->bucket) == moo->_array);
index = moo_hashoochars(ptr, len) % MOO_OBJ_GET_SIZE(moo->symtab->bucket); index = moo_hashoochars(ptr, len) % MOO_OBJ_GET_SIZE(moo->symtab->bucket);
@ -175,6 +167,7 @@ moo_oop_t moo_makesymbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len)
{ {
return find_or_make_symbol (moo, ptr, len, 1); return find_or_make_symbol (moo, ptr, len, 1);
} }
moo_oop_t moo_findsymbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len) moo_oop_t moo_findsymbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len)
{ {
return find_or_make_symbol (moo, ptr, len, 0); return find_or_make_symbol (moo, ptr, len, 0);