From: Bruno Haible Date: Mon, 12 Mar 2001 20:28:14 +0000 (+0000) Subject: Accept all kinds of comparison operators in the plural expression. X-Git-Tag: v0.10.36~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef56f35dc0450a81ab34c1d142884c46a3bacc9b;p=thirdparty%2Fgettext.git Accept all kinds of comparison operators in the plural expression. --- diff --git a/intl/ChangeLog b/intl/ChangeLog index 5561e64ac..095a17bea 100644 --- a/intl/ChangeLog +++ b/intl/ChangeLog @@ -1,3 +1,13 @@ +2001-03-12 Bruno Haible + + * gettextP.h (struct expression): Add operators less_than, + greater_than, less_or_equal, greater_or_equal. + * plural.y ('<', '>', LE, GE): New operators. + (exp): Add rules with these operators. + (FREE_EXPRESSION): Recognize these operators. + (yylex): Don't skip "\\n". Recognize '<', '>', LE, GE operators. + * dcigettext.c (plural_eval): Recognize these operators. + 2001-03-10 Bruno Haible * Makefile.in (libintl.la): Pass -liconv and flag -no-undefined. diff --git a/intl/dcigettext.c b/intl/dcigettext.c index a34c7916f..982689bf4 100644 --- a/intl/dcigettext.c +++ b/intl/dcigettext.c @@ -1009,6 +1009,18 @@ plural_eval (pexp, n) case minus: return (plural_eval (pexp->val.args2.left, n) - plural_eval (pexp->val.args2.right, n)); + case less_than: + return (plural_eval (pexp->val.args2.left, n) + < plural_eval (pexp->val.args2.right, n)); + case greater_than: + return (plural_eval (pexp->val.args2.left, n) + > plural_eval (pexp->val.args2.right, n)); + case less_or_equal: + return (plural_eval (pexp->val.args2.left, n) + <= plural_eval (pexp->val.args2.right, n)); + case greater_or_equal: + return (plural_eval (pexp->val.args2.left, n) + >= plural_eval (pexp->val.args2.right, n)); case equal: return (plural_eval (pexp->val.args2.left, n) == plural_eval (pexp->val.args2.right, n)); diff --git a/intl/gettextP.h b/intl/gettextP.h index fe12fce12..0c8520cdf 100644 --- a/intl/gettextP.h +++ b/intl/gettextP.h @@ -84,8 +84,12 @@ struct expression module, /* Module operation. */ plus, /* Addition. */ minus, /* Subtraction. */ - equal, /* Comparision for equality. */ - not_equal, /* Comparision for inequality. */ + less_than, /* Comparison. */ + greater_than, /* Comparison. */ + less_or_equal, /* Comparison. */ + greater_or_equal, /* Comparison. */ + equal, /* Comparison for equality. */ + not_equal, /* Comparison for inequality. */ land, /* Logical AND. */ lor, /* Logical OR. */ qmop /* Question mark operator. */ diff --git a/intl/plural.y b/intl/plural.y index 54dc7b257..f835fa5f2 100644 --- a/intl/plural.y +++ b/intl/plural.y @@ -60,12 +60,16 @@ static int yylex PARAMS ((YYSTYPE *lval, const char **pexp)); static void yyerror PARAMS ((const char *str)); %} -%left '?' -%left '|' -%left '&' -%left '=', '!' -%left '+', '-' -%left '*', '/', '%' +/* This declares that all operators are left-associative, and that the + precedence order is the same as in C. There is no unary minus. */ +%left '?' /* ? */ +%left '|' /* || */ +%left '&' /* && */ +%left '=', '!' /* == != */ +%nonassoc '<', '>', LE, GE /* < > <= >= */ +%left '+', '-' /* + - */ +%left '*', '/', '%' /* * / % */ + %token NUMBER %type exp @@ -102,6 +106,26 @@ exp: exp '?' exp ':' exp if (($$ = new_exp_2 (not_equal, $1, $3)) == NULL) YYABORT } + | exp '<' exp + { + if (($$ = new_exp_2 (less_than, $1, $3)) == NULL) + YYABORT + } + | exp '>' exp + { + if (($$ = new_exp_2 (greater_than, $1, $3)) == NULL) + YYABORT + } + | exp LE exp + { + if (($$ = new_exp_2 (less_or_equal, $1, $3)) == NULL) + YYABORT + } + | exp GE exp + { + if (($$ = new_exp_2 (greater_or_equal, $1, $3)) == NULL) + YYABORT + } | exp '+' exp { if (($$ = new_exp_2 (plus, $1, $3)) == NULL) @@ -233,6 +257,10 @@ FREE_EXPRESSION (exp) case module: case plus: case minus: + case less_than: + case greater_than: + case less_or_equal: + case greater_or_equal: case equal: case not_equal: case land: @@ -259,12 +287,6 @@ yylex (lval, pexp) while (1) { - if (exp[0] == '\\' && exp[1] == '\n') - { - exp += 2; - continue; - } - if (exp[0] == '\0') { *pexp = exp; @@ -311,6 +333,22 @@ yylex (lval, pexp) result = YYERRCODE; break; + case '<': + if (exp[0] == '=') + { + ++exp; + result = LE; + } + break; + + case '>': + if (exp[0] == '=') + { + ++exp; + result = GE; + } + break; + case 'n': case '*': case '/':