]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Refactor.
authorBruno Haible <bruno@clisp.org>
Fri, 8 Nov 2024 14:54:46 +0000 (15:54 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 8 Nov 2024 14:54:46 +0000 (15:54 +0100)
* 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.

gettext-tools/src/cldr-plural-exp.c
gettext-tools/src/cldr-plural-exp.h
gettext-tools/src/cldr-plural.y

index 60d3d0bafe2d72dae5d88af89e3b29aa8219bee2..32f9fd2a22058c96c2a260cd0b63855998b6b584 100644 (file)
@@ -1,5 +1,5 @@
-/* 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.
 
@@ -28,7 +28,6 @@
 #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
@@ -62,6 +61,14 @@ cldr_plural_range_list_free (struct cldr_plural_range_list_ty *ranges)
   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)
 {
@@ -76,14 +83,6 @@ 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)
 {
@@ -101,23 +100,6 @@ cldr_plural_rule_list_free (struct cldr_plural_rule_list_ty *rules)
   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)                            \
index 2e5d8229628beb191f7f7ae4fd97a1272e4af85b..fe1d3d85f1cfd9b2d84f92ab1f17dadba084c58e 100644 (file)
@@ -1,5 +1,5 @@
-/* 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.
 
@@ -112,29 +112,26 @@ struct cldr_plural_rule_list_ty
   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
index 05c1b56ecaf9b7c444f9c861718ea62ef8a526e2..ad6d5f82ad91a53e7cdd3508c43ec6b0587cbce0 100644 (file)
@@ -1,4 +1,4 @@
-/* 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.  */
 
@@ -119,6 +114,25 @@ new_range (struct cldr_plural_operand_ty *start,
   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"
@@ -272,17 +286,19 @@ sample_ellipsis: %empty
         ;
 
 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)
 {
@@ -464,3 +480,22 @@ yyerror (struct cldr_plural_parse_args *arg, char const *s)
 {
   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;
+}