Skip to content

Commit

Permalink
ICU-22902 Remove support for Unsupported, Private & Reserved constructs
Browse files Browse the repository at this point in the history
Matching PR #883 in the message-format-wg repo.

Also move spec tests for unsupported statements and expressions into new files
to serve as syntax error tests.
  • Loading branch information
catamorphism committed Sep 21, 2024
1 parent 5f9f8b2 commit 2f348f4
Show file tree
Hide file tree
Showing 20 changed files with 109 additions and 1,577 deletions.
4 changes: 1 addition & 3 deletions icu4c/source/common/unicode/utypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,15 +597,13 @@ typedef enum UErrorCode {
U_MF_MISSING_SELECTOR_ANNOTATION_ERROR, /**< A selector expression evaluates to an unannotated operand. @internal ICU 75 technology preview @deprecated This API is for technology preview only. */
U_MF_DUPLICATE_DECLARATION_ERROR, /**< The same variable is declared in more than one .local or .input declaration. @internal ICU 75 technology preview @deprecated This API is for technology preview only. */
U_MF_OPERAND_MISMATCH_ERROR, /**< An operand provided to a function does not have the required form for that function @internal ICU 75 technology preview @deprecated This API is for technology preview only. */
U_MF_UNSUPPORTED_STATEMENT_ERROR, /**< A message includes a reserved statement. @internal ICU 75 technology preview @deprecated This API is for technology preview only. */
U_MF_UNSUPPORTED_EXPRESSION_ERROR, /**< A message includes syntax reserved for future standardization or private implementation use. @internal ICU 75 technology preview @deprecated This API is for technology preview only. */
U_MF_DUPLICATE_VARIANT_ERROR, /**< A message includes a variant with the same key list as another variant. @internal ICU 76 technology preview @deprecated This API is for technology preview only. */
#ifndef U_HIDE_DEPRECATED_API
/**
* One more than the highest normal formatting API error code.
* @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
*/
U_FMT_PARSE_ERROR_LIMIT = 0x10122,
U_FMT_PARSE_ERROR_LIMIT = 0x10120,
#endif // U_HIDE_DEPRECATED_API

/*
Expand Down
2 changes: 0 additions & 2 deletions icu4c/source/common/utypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ _uFmtErrorName[U_FMT_PARSE_ERROR_LIMIT - U_FMT_PARSE_ERROR_START] = {
"U_MF_MISSING_SELECTOR_ANNOTATION_ERROR",
"U_MF_DUPLICATE_DECLARATION_ERROR",
"U_MF_OPERAND_MISMATCH_ERROR",
"U_MF_UNSUPPORTED_STATEMENT_ERROR",
"U_MF_UNSUPPORTED_EXPRESSION_ERROR",
"U_MF_DUPLICATE_VARIANT_ERROR"
};

Expand Down
30 changes: 0 additions & 30 deletions icu4c/source/i18n/messageformat2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,24 +241,6 @@ FunctionOptions MessageFormatter::resolveOptions(const Environment& env, const O
return FormattedPlaceholder(fallback);
}

// Per https://github.com/unicode-org/message-format-wg/blob/main/spec/formatting.md#fallback-resolution
static UnicodeString reservedFallback (const Expression& e) {
UErrorCode localErrorCode = U_ZERO_ERROR;
const Operator* rator = e.getOperator(localErrorCode);
U_ASSERT(U_SUCCESS(localErrorCode));
const Reserved& r = rator->asReserved();

// An empty Reserved isn't representable in the syntax
U_ASSERT(r.numParts() > 0);

const UnicodeString& contents = r.getPart(0).unquoted();
// Parts should never be empty
U_ASSERT(contents.length() > 0);

// Return first character of string
return UnicodeString(contents, 0, 1);
}

// Formats an expression using `globalEnv` for the values of variables
[[nodiscard]] FormattedPlaceholder MessageFormatter::formatExpression(const Environment& globalEnv,
const Expression& expr,
Expand All @@ -268,12 +250,6 @@ static UnicodeString reservedFallback (const Expression& e) {
return {};
}

// Formatting error
if (expr.isReserved()) {
context.getErrors().setReservedError(status);
return FormattedPlaceholder(reservedFallback(expr));
}

const Operand& rand = expr.getOperand();
// Format the operand (formatOperand handles the case of a null operand)
FormattedPlaceholder randVal = formatOperand(globalEnv, rand, context, status);
Expand Down Expand Up @@ -675,12 +651,6 @@ ResolvedSelector MessageFormatter::resolveVariables(const Environment& env,
return {};
}

// A `reserved` is an error
if (expr.isReserved()) {
context.getErrors().setReservedError(status);
return ResolvedSelector(FormattedPlaceholder(reservedFallback(expr)));
}

// Function call -- resolve the operand and options
if (expr.isFunctionCall()) {
const Operator* rator = expr.getOperator(status);
Expand Down
22 changes: 5 additions & 17 deletions icu4c/source/i18n/messageformat2_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ void Checker::addFreeVars(TypeEnvironment& t, const OptionMap& opts, UErrorCode&
void Checker::addFreeVars(TypeEnvironment& t, const Operator& rator, UErrorCode& status) {
CHECK_ERROR(status);

if (!rator.isReserved()) {
addFreeVars(t, rator.getOptionsInternal(), status);
}
addFreeVars(t, rator.getOptionsInternal(), status);
}

void Checker::addFreeVars(TypeEnvironment& t, const Expression& rhs, UErrorCode& status) {
Expand Down Expand Up @@ -213,12 +211,10 @@ void Checker::requireAnnotated(const TypeEnvironment& t, const Expression& selec
if (selectorExpr.isFunctionCall()) {
return; // No error
}
if (!selectorExpr.isReserved()) {
const Operand& rand = selectorExpr.getOperand();
if (rand.isVariable()) {
if (t.get(rand.asVariable()) == TypeEnvironment::Type::Annotated) {
return; // No error
}
const Operand& rand = selectorExpr.getOperand();
if (rand.isVariable()) {
if (t.get(rand.asVariable()) == TypeEnvironment::Type::Annotated) {
return; // No error
}
}
// If this code is reached, an error was detected
Expand All @@ -240,9 +236,6 @@ TypeEnvironment::Type typeOf(TypeEnvironment& t, const Expression& expr) {
if (expr.isFunctionCall()) {
return TypeEnvironment::Type::Annotated;
}
if (expr.isReserved()) {
return TypeEnvironment::Type::Unannotated;
}
const Operand& rand = expr.getOperand();
U_ASSERT(!rand.isNull());
if (rand.isLiteral()) {
Expand Down Expand Up @@ -296,11 +289,6 @@ void Checker::checkDeclarations(TypeEnvironment& t, UErrorCode& status) {
// Next, extend the type environment with a binding from lhs to its type
t.extend(lhs, typeOf(t, rhs), status);
}

// Check for unsupported statements
if (dataModel.unsupportedStatementsLen > 0) {
errors.addError(StaticErrorType::UnsupportedStatementError, status);
}
}

void Checker::check(UErrorCode& status) {
Expand Down
Loading

0 comments on commit 2f348f4

Please sign in to comment.