PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/gettext/gettext-tools/src/po-gram-gen.y

https://bitbucket.org/koron/vim-kaoriya
Happy | 293 lines | 262 code | 31 blank | 0 comment | 0 complexity | 2d31c7da3a9bc739e71e69a1b4f90db0 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-2.0
  1. /* GNU gettext - internationalization aids
  2. Copyright (C) 1995-1996, 1998, 2000-2001, 2003 Free Software Foundation, Inc.
  3. This file was written by Peter Miller <pmiller@agso.gov.au>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  15. %{
  16. #ifdef HAVE_CONFIG_H
  17. # include "config.h"
  18. #endif
  19. /* Specification. */
  20. #include "po-gram.h"
  21. #include <stdbool.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include "str-list.h"
  26. #include "po-lex.h"
  27. #include "po-charset.h"
  28. #include "error.h"
  29. #include "xalloc.h"
  30. #include "gettext.h"
  31. #include "read-po-abstract.h"
  32. #define _(str) gettext (str)
  33. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
  34. as well as gratuitiously global symbol names, so we can have multiple
  35. yacc generated parsers in the same program. Note that these are only
  36. the variables produced by yacc. If other parser generators (bison,
  37. byacc, etc) produce additional global names that conflict at link time,
  38. then those parser generators need to be fixed instead of adding those
  39. names to this list. */
  40. #define yymaxdepth po_gram_maxdepth
  41. #define yyparse po_gram_parse
  42. #define yylex po_gram_lex
  43. #define yyerror po_gram_error
  44. #define yylval po_gram_lval
  45. #define yychar po_gram_char
  46. #define yydebug po_gram_debug
  47. #define yypact po_gram_pact
  48. #define yyr1 po_gram_r1
  49. #define yyr2 po_gram_r2
  50. #define yydef po_gram_def
  51. #define yychk po_gram_chk
  52. #define yypgo po_gram_pgo
  53. #define yyact po_gram_act
  54. #define yyexca po_gram_exca
  55. #define yyerrflag po_gram_errflag
  56. #define yynerrs po_gram_nerrs
  57. #define yyps po_gram_ps
  58. #define yypv po_gram_pv
  59. #define yys po_gram_s
  60. #define yy_yys po_gram_yys
  61. #define yystate po_gram_state
  62. #define yytmp po_gram_tmp
  63. #define yyv po_gram_v
  64. #define yy_yyv po_gram_yyv
  65. #define yyval po_gram_val
  66. #define yylloc po_gram_lloc
  67. #define yyreds po_gram_reds /* With YYDEBUG defined */
  68. #define yytoks po_gram_toks /* With YYDEBUG defined */
  69. #define yylhs po_gram_yylhs
  70. #define yylen po_gram_yylen
  71. #define yydefred po_gram_yydefred
  72. #define yydgoto po_gram_yydgoto
  73. #define yysindex po_gram_yysindex
  74. #define yyrindex po_gram_yyrindex
  75. #define yygindex po_gram_yygindex
  76. #define yytable po_gram_yytable
  77. #define yycheck po_gram_yycheck
  78. static long plural_counter;
  79. #define check_obsolete(value1,value2) \
  80. if ((value1).obsolete != (value2).obsolete) \
  81. po_gram_error_at_line (&(value2).pos, _("inconsistent use of #~"));
  82. static inline void
  83. do_callback_message (char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural,
  84. char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos,
  85. bool obsolete)
  86. {
  87. /* Test for header entry. Ignore fuzziness of the header entry. */
  88. if (msgid[0] == '\0' && !obsolete)
  89. po_lex_charset_set (msgstr, gram_pos.file_name);
  90. po_callback_message (msgid, msgid_pos, msgid_plural,
  91. msgstr, msgstr_len, msgstr_pos,
  92. false, obsolete);
  93. }
  94. %}
  95. %token COMMENT
  96. %token DOMAIN
  97. %token JUNK
  98. %token MSGID
  99. %token MSGID_PLURAL
  100. %token MSGSTR
  101. %token NAME
  102. %token '[' ']'
  103. %token NUMBER
  104. %token STRING
  105. %union
  106. {
  107. struct { char *string; lex_pos_ty pos; bool obsolete; } string;
  108. struct { string_list_ty stringlist; lex_pos_ty pos; bool obsolete; } stringlist;
  109. struct { long number; lex_pos_ty pos; bool obsolete; } number;
  110. struct { lex_pos_ty pos; bool obsolete; } pos;
  111. struct { struct msgstr_def rhs; lex_pos_ty pos; bool obsolete; } rhs;
  112. }
  113. %type <string> STRING COMMENT NAME msgid_pluralform
  114. %type <stringlist> string_list
  115. %type <number> NUMBER
  116. %type <pos> DOMAIN MSGID MSGID_PLURAL MSGSTR '[' ']'
  117. %type <rhs> pluralform pluralform_list
  118. %right MSGSTR
  119. %%
  120. msgfmt
  121. : /* empty */
  122. | msgfmt comment
  123. | msgfmt domain
  124. | msgfmt message
  125. | msgfmt error
  126. ;
  127. domain
  128. : DOMAIN STRING
  129. {
  130. po_callback_domain ($2.string);
  131. }
  132. ;
  133. message
  134. : MSGID string_list MSGSTR string_list
  135. {
  136. char *string2 = string_list_concat_destroy (&$2.stringlist);
  137. char *string4 = string_list_concat_destroy (&$4.stringlist);
  138. check_obsolete ($1, $2);
  139. check_obsolete ($1, $3);
  140. check_obsolete ($1, $4);
  141. if (!$1.obsolete || pass_obsolete_entries)
  142. do_callback_message (string2, &$1.pos, NULL,
  143. string4, strlen (string4) + 1, &$3.pos,
  144. $1.obsolete);
  145. else
  146. {
  147. free (string2);
  148. free (string4);
  149. }
  150. }
  151. | MSGID string_list msgid_pluralform pluralform_list
  152. {
  153. char *string2 = string_list_concat_destroy (&$2.stringlist);
  154. check_obsolete ($1, $2);
  155. check_obsolete ($1, $3);
  156. check_obsolete ($1, $4);
  157. if (!$1.obsolete || pass_obsolete_entries)
  158. do_callback_message (string2, &$1.pos, $3.string,
  159. $4.rhs.msgstr, $4.rhs.msgstr_len, &$4.pos,
  160. $1.obsolete);
  161. else
  162. {
  163. free (string2);
  164. free ($3.string);
  165. free ($4.rhs.msgstr);
  166. }
  167. }
  168. | MSGID string_list msgid_pluralform
  169. {
  170. check_obsolete ($1, $2);
  171. check_obsolete ($1, $3);
  172. po_gram_error_at_line (&$1.pos, _("missing `msgstr[]' section"));
  173. string_list_destroy (&$2.stringlist);
  174. free ($3.string);
  175. }
  176. | MSGID string_list pluralform_list
  177. {
  178. check_obsolete ($1, $2);
  179. check_obsolete ($1, $3);
  180. po_gram_error_at_line (&$1.pos, _("missing `msgid_plural' section"));
  181. string_list_destroy (&$2.stringlist);
  182. free ($3.rhs.msgstr);
  183. }
  184. | MSGID string_list
  185. {
  186. check_obsolete ($1, $2);
  187. po_gram_error_at_line (&$1.pos, _("missing `msgstr' section"));
  188. string_list_destroy (&$2.stringlist);
  189. }
  190. ;
  191. msgid_pluralform
  192. : MSGID_PLURAL string_list
  193. {
  194. check_obsolete ($1, $2);
  195. plural_counter = 0;
  196. $$.string = string_list_concat_destroy (&$2.stringlist);
  197. $$.pos = $1.pos;
  198. $$.obsolete = $1.obsolete;
  199. }
  200. ;
  201. pluralform_list
  202. : pluralform
  203. {
  204. $$ = $1;
  205. }
  206. | pluralform_list pluralform
  207. {
  208. check_obsolete ($1, $2);
  209. $$.rhs.msgstr = (char *) xmalloc ($1.rhs.msgstr_len + $2.rhs.msgstr_len);
  210. memcpy ($$.rhs.msgstr, $1.rhs.msgstr, $1.rhs.msgstr_len);
  211. memcpy ($$.rhs.msgstr + $1.rhs.msgstr_len, $2.rhs.msgstr, $2.rhs.msgstr_len);
  212. $$.rhs.msgstr_len = $1.rhs.msgstr_len + $2.rhs.msgstr_len;
  213. free ($1.rhs.msgstr);
  214. free ($2.rhs.msgstr);
  215. $$.pos = $1.pos;
  216. $$.obsolete = $1.obsolete;
  217. }
  218. ;
  219. pluralform
  220. : MSGSTR '[' NUMBER ']' string_list
  221. {
  222. check_obsolete ($1, $2);
  223. check_obsolete ($1, $3);
  224. check_obsolete ($1, $4);
  225. check_obsolete ($1, $5);
  226. if ($3.number != plural_counter)
  227. {
  228. if (plural_counter == 0)
  229. po_gram_error_at_line (&$1.pos, _("first plural form has nonzero index"));
  230. else
  231. po_gram_error_at_line (&$1.pos, _("plural form has wrong index"));
  232. }
  233. plural_counter++;
  234. $$.rhs.msgstr = string_list_concat_destroy (&$5.stringlist);
  235. $$.rhs.msgstr_len = strlen ($$.rhs.msgstr) + 1;
  236. $$.pos = $1.pos;
  237. $$.obsolete = $1.obsolete;
  238. }
  239. ;
  240. string_list
  241. : STRING
  242. {
  243. string_list_init (&$$.stringlist);
  244. string_list_append (&$$.stringlist, $1.string);
  245. $$.pos = $1.pos;
  246. $$.obsolete = $1.obsolete;
  247. }
  248. | string_list STRING
  249. {
  250. check_obsolete ($1, $2);
  251. $$.stringlist = $1.stringlist;
  252. string_list_append (&$$.stringlist, $2.string);
  253. $$.pos = $1.pos;
  254. $$.obsolete = $1.obsolete;
  255. }
  256. ;
  257. comment
  258. : COMMENT
  259. {
  260. po_callback_comment_dispatcher ($1.string);
  261. }
  262. ;