fixed a tokenization bug in getting a empty string literal.
allowed a zero-length symbol to be created
This commit is contained in:
parent
93e776a9d8
commit
8442968f9c
@ -1238,13 +1238,20 @@ static int get_strlit (moo_t* moo)
|
||||
* normal-character := character-except-single-quote
|
||||
*/
|
||||
|
||||
moo_ooci_t c = moo->c->lxc.c;
|
||||
SET_TOKEN_TYPE (moo, MOO_IOTOK_STRLIT);
|
||||
moo_ooci_t oc, c;
|
||||
|
||||
oc = moo->c->lxc.c; /* opening quote */
|
||||
|
||||
SET_TOKEN_TYPE (moo, MOO_IOTOK_STRLIT);
|
||||
GET_CHAR_TO (moo, c);
|
||||
|
||||
if (c != oc)
|
||||
{
|
||||
do
|
||||
{
|
||||
do
|
||||
{
|
||||
in_strlit:
|
||||
ADD_TOKEN_CHAR (moo, c);
|
||||
GET_CHAR_TO (moo, c);
|
||||
|
||||
@ -1255,13 +1262,18 @@ static int get_strlit (moo_t* moo)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
while (c != '\'');
|
||||
while (c != oc);
|
||||
|
||||
/* 'c' must be a single quote at this point*/
|
||||
GET_CHAR_TO (moo, c);
|
||||
}
|
||||
while (c == '\''); /* if the next character is a single quote,
|
||||
it becomes a literal single quote character. */
|
||||
while (c == oc); /* if the next character is a single quote, 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);
|
||||
return 0;
|
||||
@ -1509,7 +1521,6 @@ retry:
|
||||
break;
|
||||
|
||||
case '\'': /* string literal */
|
||||
GET_CHAR (moo);
|
||||
if (get_strlit(moo) <= -1) return -1;
|
||||
break;
|
||||
|
||||
@ -1612,9 +1623,8 @@ retry:
|
||||
|
||||
case '\'':
|
||||
/* quoted symbol literal */
|
||||
GET_CHAR (moo);
|
||||
if (get_strlit(moo) <= -1) return -1;
|
||||
SET_TOKEN_TYPE (moo, MOO_IOTOK_SYMLIT);
|
||||
if (get_strlit(moo) <= -1) return -1; /* reuse the string literal tokenizer */
|
||||
SET_TOKEN_TYPE (moo, MOO_IOTOK_SYMLIT); /* change the symbol type to symbol */
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -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_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);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user