• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Resolving ambiguity of argument lists: Progressive parsing of an
2    argument list, keeping track of all possibilities.
3    Copyright (C) 2001-2018 Free Software Foundation, Inc.
4 
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
17 
18 #ifndef _XGETTEXT_ARGLIST_PARSER_H
19 #define _XGETTEXT_ARGLIST_PARSER_H
20 
21 #include <stdbool.h>
22 #include <stddef.h>
23 
24 #include "pos.h"
25 #include "rc-str-list.h"
26 #include "str-list.h"
27 
28 #include "xg-mixed-string.h"
29 #include "xg-arglist-context.h"
30 #include "xg-arglist-callshape.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 
37 /* Represents the progressive parsing of an argument list w.r.t. a single
38    'struct callshape'.  */
39 struct partial_call
40 {
41   int argnumc;                  /* number of context argument, 0 when seen */
42   int argnum1;                  /* number of singular argument, 0 when seen */
43   int argnum2;                  /* number of plural argument, 0 when seen */
44   bool argnum1_glib_context;    /* argument argnum1 has the syntax "ctxt|msgid" */
45   bool argnum2_glib_context;    /* argument argnum2 has the syntax "ctxt|msgid" */
46   int argtotal;                 /* total number of arguments, 0 if unspecified */
47   string_list_ty xcomments;     /* auto-extracted comments */
48   mixed_string_ty *msgctxt;     /* context - owned mixed_string, or NULL */
49   lex_pos_ty msgctxt_pos;
50   mixed_string_ty *msgid;       /* msgid - owned mixed_string, or NULL */
51   flag_context_ty msgid_context;
52   lex_pos_ty msgid_pos;
53   refcounted_string_list_ty *msgid_comment;
54   bool msgid_comment_is_utf8;
55   mixed_string_ty *msgid_plural; /* msgid_plural - owned mixed_string, or NULL */
56   flag_context_ty msgid_plural_context;
57   lex_pos_ty msgid_plural_pos;
58 };
59 
60 /* Represents the progressive parsing of an argument list w.r.t. an entire
61    'struct callshapes'.  */
62 struct arglist_parser
63 {
64   message_list_ty *mlp;         /* list where the message shall be added */
65   const char *keyword;          /* the keyword, not NUL terminated */
66   size_t keyword_len;           /* the keyword's length */
67   bool next_is_msgctxt;         /* true if the next argument is the msgctxt */
68   size_t nalternatives;         /* number of partial_call alternatives */
69   struct partial_call alternative[1]; /* partial_call alternatives */
70 };
71 
72 /* Creates a fresh arglist_parser recognizing calls.
73    You can pass shapes = NULL for a parser not recognizing any calls.  */
74 extern struct arglist_parser * arglist_parser_alloc (message_list_ty *mlp,
75                                                      const struct callshapes *shapes);
76 /* Clones an arglist_parser.  */
77 extern struct arglist_parser * arglist_parser_clone (struct arglist_parser *ap);
78 /* Adds a string argument to an arglist_parser.  ARGNUM must be > 0.
79    STRING must be a mixed_string; its ownership is passed to the callee.
80    FILE_NAME must be allocated with indefinite extent.
81    COMMENT may be savable_comment, or it may be a saved copy of savable_comment
82    (then add_reference must be used when saving it, and drop_reference while
83    dropping it).  Clear savable_comment.
84    COMMENT_IS_UTF8 must be true if COMMENT has already been converted to UTF-8.
85  */
86 extern void arglist_parser_remember (struct arglist_parser *ap,
87                                      int argnum, mixed_string_ty *string,
88                                      flag_context_ty context,
89                                      char *file_name, size_t line_number,
90                                      refcounted_string_list_ty *comment,
91                                      bool comment_is_utf8);
92 /* Adds a string argument as msgctxt to an arglist_parser, without incrementing
93    the current argument number.
94    STRING must be a mixed_string; its ownership is passed to the callee.
95    FILE_NAME must be allocated with indefinite extent.  */
96 extern void arglist_parser_remember_msgctxt (struct arglist_parser *ap,
97                                              mixed_string_ty *string,
98                                              flag_context_ty context,
99                                              char *file_name, size_t line_number);
100 /* Tests whether an arglist_parser has is not waiting for more arguments after
101    argument ARGNUM.  */
102 extern bool arglist_parser_decidedp (struct arglist_parser *ap, int argnum);
103 /* Terminates the processing of an arglist_parser after argument ARGNUM and
104    deletes it.  */
105 extern void arglist_parser_done (struct arglist_parser *ap, int argnum);
106 
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 
113 #endif /* _XGETTEXT_ARGLIST_PARSER_H */
114