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,13 +1238,20 @@ 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);
oc = moo->c->lxc.c; /* opening quote */
SET_TOKEN_TYPE (moo, MOO_IOTOK_STRLIT);
GET_CHAR_TO (moo, c);
if (c != oc)
{
do do
{ {
do do
{ {
in_strlit:
ADD_TOKEN_CHAR (moo, c); ADD_TOKEN_CHAR (moo, c);
GET_CHAR_TO (moo, c); GET_CHAR_TO (moo, c);
@ -1255,13 +1262,18 @@ static int get_strlit (moo_t* moo)
return -1; return -1;
} }
} }
while (c != '\''); while (c != oc);
/* 'c' must be a single quote at this point*/ /* 'c' must be a single quote at this point*/
GET_CHAR_TO (moo, c); GET_CHAR_TO (moo, c);
} }
while (c == '\''); /* if the next character is a single quote, while (c == oc); /* if the next character is a single quote, it becomes a literal single quote character. */
it becomes a literal single quote character. */ }
else
{
GET_CHAR_TO (moo, c);
if (c == oc) goto in_strlit;
}
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);