L_PARSE_REPEAT_NO_UNTIL,
L_PARSE_REPEAT_NO_SEMI,
L_PARSE_BODY_WRONG_ITEM,
- L_PARSE_FOR_NO_TO = 2020
+ L_PARSE_FOR_NO_TO = 2020,
+ L_PARSE_LIST_NO_COMMA
};
RplASItem* RplMFParser::parseList()
{
RplASListConstant* rc = new RplASListConstant();
+ RplASVariant& varList = rc->value();
+ RplASListOfVariants* list = static_cast<RplASListOfVariants*>
+ (varList.asObject(NULL));
rc->setPosition(m_lexer.currentPosition());
-
+ RplASVariant* variant;
bool again = true;
RplToken* token;
RplToken* token2;
if (token->isOperator(O_LBRACKET))
again = false;
else{
+ variant = NULL;
m_lexer.saveLastToken();
- RplASVariant* variant = NULL;
token2 = m_lexer.nextNonSpaceToken();
if (token2->isOperator(O_COMMA)){
switch(token->tokenType()){
case TOKEN_NUMBER:
+ // freed in the destructor of varList (~RplASVariant()):
variant = new RplASVariant();
variant->setInt(token->asInteger());
break;
case TOKEN_STRING:
+ // freed in the destructor of varList (~RplASVariant()):
variant = new RplASVariant();
variant->setString(token->toString());
break;
case TOKEN_REAL:
+ // freed in the destructor of varList (~RplASVariant()):
variant = new RplASVariant();
variant->setFloat(token->asReal());
break;
switch(token->id()){
case K_TRUE:
case K_FALSE:
+ // freed in the destructor of varList (~RplASVariant()):
variant = new RplASVariant();
variant->setBool(token->id() == K_TRUE);
break;
case K_NONE:
+ // freed in the destructor of varList (~RplASVariant()):
variant = new RplASVariant();
break;
default:
}
if (variant == NULL){
m_lexer.undoLastToken2();
- RplASExprStatement* expr = parseExprStatement();
- expr->successor(rc->child());
+ RplASExprStatement* expr = dynamic_cast<RplASExprStatement*>
+ (parseExprStatement());
+ // chaining per m_successor is for freeing in destruction:
+ expr->setSuccessor(rc->child());
rc->setChild(expr);
- variant = RplASFormula::m_instance.newValueInstance(expr);
+ variant->setObject(expr, &RplASFormula::m_instance);
+ token = m_lexer.currentToken();
+ if (token->isOperator(O_RBRACKET))
+ again = false;
+ else if (token->isOperator(O_COMMA))
+ m_lexer.undoLastToken();
+ else
+ syntaxError(L_PARSE_LIST_NO_COMMA, "',' or ']' expected");
}
+ list->append(variant);
}
}
return rc;