* gettext-tools/src/cldr-plural.y: Untabify.
(struct cldr_plural_parse_args): New type, moved here from
gettext-tools/src/cldr-plural-exp.h.
(cldr_plural_parse): New function, moved here from
gettext-tools/src/cldr-plural-exp.c.
* gettext-tools/src/cldr-plural-exp.h: Reorder declarations.
(struct cldr_plural_parse_args): Remove declaration.
* gettext-tools/src/cldr-plural-exp.c: Don't include cldr-plural.h. Reorder
functions.
(cldr_plural_parse): Remove function.
-/* Unicode CLDR plural rule parser and converter
- Copyright (C) 2015, 2018-2020 Free Software Foundation, Inc.
+/* Unicode CLDR plural rule parser and converter.
+ Copyright (C) 2015-2024 Free Software Foundation, Inc.
This file was written by Daiki Ueno <ueno@gnu.org>, 2015.
#include "xalloc.h"
#include "cldr-plural-exp.h"
-#include "cldr-plural.h"
/* The grammar of Unicode CLDR plural rules is defined at:
https://unicode.org/reports/tr35/tr35-numbers.html#Plural_rules_syntax
free (ranges);
}
+void
+cldr_plural_relation_free (struct cldr_plural_relation_ty *relation)
+{
+ free (relation->expression);
+ cldr_plural_range_list_free (relation->ranges);
+ free (relation);
+}
+
void
cldr_plural_condition_free (struct cldr_plural_condition_ty *condition)
{
free (condition);
}
-void
-cldr_plural_relation_free (struct cldr_plural_relation_ty *relation)
-{
- free (relation->expression);
- cldr_plural_range_list_free (relation->ranges);
- free (relation);
-}
-
static void
cldr_plural_rule_free (struct cldr_plural_rule_ty *rule)
{
free (rules);
}
-struct cldr_plural_rule_list_ty *
-cldr_plural_parse (const char *input)
-{
- struct cldr_plural_parse_args arg;
-
- memset (&arg, 0, sizeof (struct cldr_plural_parse_args));
- arg.cp = input;
- arg.cp_end = input + strlen (input);
- arg.result = XMALLOC (struct cldr_plural_rule_list_ty);
- memset (arg.result, 0, sizeof (struct cldr_plural_rule_list_ty));
-
- if (yyparse (&arg) != 0)
- return NULL;
-
- return arg.result;
-}
-
#define OPERAND_ZERO_P(o) \
(((o)->type == CLDR_PLURAL_OPERAND_INTEGER \
&& (o)->value.ival == 0) \
-/* Unicode CLDR plural rule parser and converter
- Copyright (C) 2015, 2018 Free Software Foundation, Inc.
+/* Unicode CLDR plural rule parser and converter.
+ Copyright (C) 2015-2024 Free Software Foundation, Inc.
This file was written by Daiki Ueno <ueno@gnu.org>, 2015.
size_t nitems_max;
};
-struct cldr_plural_parse_args
-{
- const char *cp;
- const char *cp_end;
- struct cldr_plural_rule_list_ty *result;
-};
+/* Defined in cldr-plural-exp.c. */
extern void
cldr_plural_range_free (struct cldr_plural_range_ty *range);
extern void
cldr_plural_range_list_free (struct cldr_plural_range_list_ty *ranges);
extern void
-cldr_plural_condition_free (struct cldr_plural_condition_ty *condition);
-extern void
cldr_plural_relation_free (struct cldr_plural_relation_ty *relation);
-
-extern struct cldr_plural_rule_list_ty *
-cldr_plural_parse (const char *input);
+extern void
+cldr_plural_condition_free (struct cldr_plural_condition_ty *condition);
extern void
cldr_plural_rule_list_free (struct cldr_plural_rule_list_ty *rules);
extern void
cldr_plural_rule_list_print (struct cldr_plural_rule_list_ty *rules, FILE *fp);
+/* Defined in cldr-plural.y. */
+
+extern struct cldr_plural_rule_list_ty *
+cldr_plural_parse (const char *input);
+
#ifdef __cplusplus
}
#endif
-/* Unicode CLDR plural rule parser and converter
+/* Unicode CLDR plural rule parser and converter.
Copyright (C) 2015-2024 Free Software Foundation, Inc.
This file was written by Daiki Ueno <ueno@gnu.org>, 2015.
#include "string-buffer.h"
#include "cldr-plural-exp.h"
-#include "cldr-plural.h"
-
-/* Prototypes for local functions. */
-static int yylex (YYSTYPE *lval, struct cldr_plural_parse_args *arg);
-static void yyerror (struct cldr_plural_parse_args *arg, const char *str);
/* Allocation of expressions. */
result->end = end;
return result;
}
+
+/* Internal state of the Bison-generated parser. */
+
+struct cldr_plural_parse_args
+{
+ /* The lifetime of cp, cp_end is limited to the cldr_plural_parse
+ invocation. */
+ const char *cp;
+ const char *cp_end;
+
+ struct cldr_plural_rule_list_ty *result;
+};
+
+#include "cldr-plural.h"
+
+/* Prototypes for local functions, that must come after the rules. */
+static int yylex (YYSTYPE *lval, struct cldr_plural_parse_args *arg);
+static void yyerror (struct cldr_plural_parse_args *arg, const char *str);
+
%}
%require "3.0"
;
sample_range: DECIMAL
- { free ($1); }
+ { free ($1); }
| DECIMAL '~' DECIMAL
{ free ($1); free ($3); }
| INTEGER
{ free ($1); }
| INTEGER '~' INTEGER
- { free ($1); free ($3); }
+ { free ($1); free ($3); }
;
%%
+/* Functions invoked by the Bison-generated parser. */
+
static int
yylex (YYSTYPE *lval, struct cldr_plural_parse_args *arg)
{
{
fprintf (stderr, "%s\n", s);
}
+
+/* Entry point to the parser. */
+
+struct cldr_plural_rule_list_ty *
+cldr_plural_parse (const char *input)
+{
+ struct cldr_plural_parse_args arg;
+
+ memset (&arg, 0, sizeof (struct cldr_plural_parse_args));
+ arg.cp = input;
+ arg.cp_end = input + strlen (input);
+ arg.result = XMALLOC (struct cldr_plural_rule_list_ty);
+ memset (arg.result, 0, sizeof (struct cldr_plural_rule_list_ty));
+
+ if (yyparse (&arg) != 0)
+ return NULL;
+
+ return arg.result;
+}