From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: Non-stub gettext API functions committed, ready for testing
Date: Sun, 27 Jul 2014 13:36:05 -0400 [thread overview]
Message-ID: <20140727173605.GZ4038@brightrain.aerifal.cx> (raw)
In-Reply-To: <20140727172308.GH10402@port70.net>
On Sun, Jul 27, 2014 at 07:23:09PM +0200, Szabolcs Nagy wrote:
> * Rich Felker <dalias@libc.org> [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
next prev parent reply other threads:[~2014-07-27 17:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-27 8:46 Rich Felker
2014-07-27 10:06 ` Harald Becker
2014-07-27 14:14 ` Szabolcs Nagy
2014-07-27 16:49 ` Rich Felker
2014-07-27 17:23 ` Szabolcs Nagy
2014-07-27 17:36 ` Rich Felker [this message]
2014-07-27 17:51 ` Szabolcs Nagy
2014-07-27 18:00 ` Rich Felker
2014-07-28 10:18 ` Szabolcs Nagy
2014-07-28 13:00 ` Szabolcs Nagy
2014-07-28 14:01 ` Szabolcs Nagy
2014-07-28 16:27 ` Rich Felker
2014-07-29 13:49 ` Szabolcs Nagy
2014-07-27 10:19 ` Harald Becker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140727173605.GZ4038@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).