bool parseAdditiveValueExpression(CSSParserValueList* tokens, int depth, unsigned* index, Value* result) { if (checkDepthAndIndex(&depth, *index, tokens) != OK) return false; if (!parseValueMultiplicativeExpression(tokens, depth, index, result)) return false; while (*index < tokens->size() - 1) { char operatorCharacter = operatorValue(tokens, *index); if (operatorCharacter != CalcAdd && operatorCharacter != CalcSubtract) break; ++*index; Value rhs; if (!parseValueMultiplicativeExpression(tokens, depth, index, &rhs)) return false; result->value = CSSCalcBinaryOperation::create(result->value, rhs.value, static_cast<CalcOperator>(operatorCharacter)); if (!result->value) return false; } ASSERT(*index <= tokens->size()); return true; }
bool parseAdditiveValueExpression(CSSParserTokenRange& tokens, int depth, Value* result) { if (checkDepthAndIndex(&depth, tokens) != OK) return false; if (!parseValueMultiplicativeExpression(tokens, depth, result)) return false; while (!tokens.atEnd()) { char operatorCharacter = operatorValue(tokens.peek()); if (operatorCharacter != CalcAdd && operatorCharacter != CalcSubtract) break; if ((&tokens.peek() - 1)->type() != WhitespaceToken) return false; // calc(1px+ 2px) is invalid tokens.consume(); if (tokens.peek().type() != WhitespaceToken) return false; // calc(1px +2px) is invalid tokens.consumeIncludingWhitespace(); Value rhs; if (!parseValueMultiplicativeExpression(tokens, depth, &rhs)) return false; result->value = CSSCalcBinaryOperation::createSimplified(result->value, rhs.value, static_cast<CalcOperator>(operatorCharacter)); if (!result->value) return false; } return true; }