Handling of multiple variables with comma

This commit is contained in:
Wolfgang Bumiller 2012-07-20 12:53:42 +02:00
parent 3decabaa8f
commit 2763578f8b

View file

@ -91,20 +91,18 @@ typedef struct {
} paramlist_t;
MEM_VEC_FUNCTIONS(paramlist_t, ast_value*, p)
static ast_value *parser_parse_type(parser_t *parser, bool *isfunc)
static ast_value *parser_parse_type(parser_t *parser, int basetype, bool *isfunc)
{
paramlist_t params;
ast_value *var;
lex_ctx ctx = parser_ctx(parser);
int vtype = parser_token(parser)->constval.t;
int vtype = basetype;
int temptype;
MEM_VECTOR_INIT(&params, p);
*isfunc = false;
if (!parser_next(parser))
return NULL;
if (parser->tok == '(') {
*isfunc = true;
while (true) {
@ -119,7 +117,12 @@ static ast_value *parser_parse_type(parser_t *parser, bool *isfunc)
if (parser->tok == ')')
break;
param = parser_parse_type(parser, &dummy);
temptype = parser_token(parser)->constval.t;
if (!parser_next(parser)) {
MEM_VECTOR_CLEAR(&params, p);
return NULL;
}
param = parser_parse_type(parser, temptype, &dummy);
(void)dummy;
if (!param) {
@ -218,8 +221,23 @@ static bool parser_variable(parser_t *parser, bool global)
{
bool isfunc = false;
ast_function *func = NULL;
lex_ctx ctx = parser_ctx(parser);
ast_value *var = parser_parse_type(parser, &isfunc);
lex_ctx ctx;
ast_value *var;
int basetype = parser_token(parser)->constval.t;
while (true)
{
if (!parser_next(parser)) { /* skip basetype or comma */
parseerror(parser, "expected variable declaration");
return false;
}
isfunc = false;
func = NULL;
ctx = parser_ctx(parser);
var = parser_parse_type(parser, basetype, &isfunc);
if (!var)
return false;
@ -293,6 +311,11 @@ static bool parser_variable(parser_t *parser, bool global)
return true;
}
if (parser->tok == ',') {
/* another var */
continue;
}
if (parser->tok != '=') {
parseerror(parser, "expected '=' or ';'");
return false;
@ -353,6 +376,11 @@ static bool parser_variable(parser_t *parser, bool global)
if (!parser_next(parser))
return false;
if (parser->tok == ',') {
/* another */
continue;
}
if (parser->tok != ';') {
parseerror(parser, "expected semicolon");
return false;
@ -362,6 +390,7 @@ static bool parser_variable(parser_t *parser, bool global)
return true;
}
}
static bool parser_do(parser_t *parser)
{