From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/5655 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Non-stub gettext API functions committed, ready for testing Date: Sun, 27 Jul 2014 13:36:05 -0400 Message-ID: <20140727173605.GZ4038@brightrain.aerifal.cx> References: <20140727084633.GA22355@brightrain.aerifal.cx> <53D4CF09.1050209@gmx.de> <20140727141417.GG10402@port70.net> <20140727164921.GY4038@brightrain.aerifal.cx> <20140727172308.GH10402@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1406482585 22902 80.91.229.3 (27 Jul 2014 17:36:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 27 Jul 2014 17:36:25 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-5660-gllmg-musl=m.gmane.org@lists.openwall.com Sun Jul 27 19:36:21 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1XBSMr-0008PP-T3 for gllmg-musl@plane.gmane.org; Sun, 27 Jul 2014 19:36:17 +0200 Original-Received: (qmail 11328 invoked by uid 550); 27 Jul 2014 17:36:17 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 11320 invoked from network); 27 Jul 2014 17:36:17 -0000 Content-Disposition: inline In-Reply-To: <20140727172308.GH10402@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:5655 Archived-At: On Sun, Jul 27, 2014 at 07:23:09PM +0200, Szabolcs Nagy wrote: > * Rich Felker [2014-07-27 12:49:21 -0400]: > > On Sun, Jul 27, 2014 at 04:14:18PM +0200, Szabolcs Nagy wrote: > > > it shows that a c arithmetic expression parser is needed to handle plurals > > > (and the expression has to be evaluated every time dcngettext is invoked) > > > > Not necessarily. You could cache results. Or (this is likely the more > > reasonable implementation) just hard-code the expression strings that > > are actually used for real languages and implement them in C when a > > match is found. > > > > hardcoding the strings will fail if .mo files are updated to > use different expressions > > with caching the expr has to be evaluated for every uncached n Yes. > > > Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1; > > > > > > The nplurals value must be a decimal number which specifies how many > > > different plural forms exist for this language. The string following > > > plural is an expression which is using the C language syntax. > > > Exceptions are that no negative numbers are allowed, numbers must be > > > decimal, and the only variable allowed is n. > > > > This is a very poor description. Does it allow casts? Compound > > literals? Floating point? Function calls? ...? > > > > the parser in gnu gettext: > http://git.savannah.gnu.org/cgit/gettext.git/tree/gettext-runtime/intl/plural.y > > so they implement > conditional (?:) > logic (&&, ||, !) > relational (==, !=, <, >, <=, >=) > and arithmetic (+, -, *, /, %) > operators with unsigned long args only And parentheses? >From what I can tell, that's not so bad. Anyone feel like writing an expression evaluator for it? I think recursive descent is fine as long as the length of the string being evaluated is capped at a sane length (or just keep a depth counter and abort the evaluation if it exceeds some reasonable limit). Rich