mirror of
https://https.git.savannah.gnu.org/git/gettext.git
synced 2026-01-26 15:39:11 +00:00
Refactor.
* 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.
This commit is contained in:
parent
db39e984f9
commit
55f9683ca4
@ -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) \
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
@ -30,11 +30,6 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user