3 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
4 * Copyright 2015 John Marino <draco@marino.st>
6 * This source code is derived from the illumos localedef command, and
7 * provided under BSD-style license terms by Nexenta Systems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * POSIX localedef grammar.
39 #include "localedef.h"
91 %token T_COLLATING_SYMBOL
92 %token T_COLLATING_ELEMENT
107 %token T_INT_CURR_SYMBOL
108 %token T_CURRENCY_SYMBOL
109 %token T_MON_DECIMAL_POINT
110 %token T_MON_THOUSANDS_SEP
111 %token T_POSITIVE_SIGN
112 %token T_NEGATIVE_SIGN
113 %token T_MON_GROUPING
114 %token T_INT_FRAC_DIGITS
116 %token T_P_CS_PRECEDES
117 %token T_P_SEP_BY_SPACE
118 %token T_N_CS_PRECEDES
119 %token T_N_SEP_BY_SPACE
122 %token T_INT_P_CS_PRECEDES
123 %token T_INT_N_CS_PRECEDES
124 %token T_INT_P_SEP_BY_SPACE
125 %token T_INT_N_SEP_BY_SPACE
126 %token T_INT_P_SIGN_POSN
127 %token T_INT_N_SIGN_POSN
129 %token T_DECIMAL_POINT
130 %token T_THOUSANDS_SEP
149 %token
<token
> T_NAME
150 %token
<num
> T_NUMBER
151 %token
<token
> T_SYMBOL
152 %token
<collsym
> T_COLLSYM
153 %token
<collelem
> T_COLLELEM
157 localedef
: setting_list categories
161 string : T_QUOTE charlist T_QUOTE
165 charlist
: charlist T_CHAR
175 setting_list
: setting_list setting
180 setting
: T_COM_CHAR T_CHAR T_NL
184 | T_ESC_CHAR T_CHAR T_NL
188 | T_MB_CUR_MAX T_NUMBER T_NL
192 | T_MB_CUR_MIN T_NUMBER T_NL
196 | T_CODE_SET
string T_NL
198 wchar_t *w
= get_wcs
();
199 set_wide_encoding
(to_mb_string
(w
));
202 | T_CODE_SET T_NAME T_NL
204 set_wide_encoding
($2);
208 copycat
: T_COPY T_NAME T_NL
214 wchar_t *w
= get_wcs
();
215 copy_category
(to_mb_string
(w
));
220 categories
: categories category
235 charmap
: T_CHARMAP T_NL charmap_list T_END T_CHARMAP T_NL
236 | T_WIDTH T_NL width_list T_END T_WIDTH T_NL
240 charmap_list
: charmap_list charmap_entry
245 charmap_entry
: T_SYMBOL T_CHAR
250 | T_SYMBOL T_ELLIPSIS T_SYMBOL T_CHAR
252 add_charmap_range
($1, $3, $4);
258 width_list
: width_list width_entry
262 width_entry
: T_CHAR T_NUMBER T_NL
266 | T_SYMBOL T_NUMBER T_NL
268 add_charmap_undefined
($1);
270 | T_CHAR T_ELLIPSIS T_CHAR T_NUMBER T_NL
272 add_width_range
($1, $3, $4);
274 | T_SYMBOL T_ELLIPSIS T_SYMBOL T_NUMBER T_NL
276 add_charmap_undefined
($1);
277 add_charmap_undefined
($3);
279 | T_CHAR T_ELLIPSIS T_SYMBOL T_NUMBER T_NL
282 add_charmap_undefined
($3);
284 | T_SYMBOL T_ELLIPSIS T_CHAR T_NUMBER T_NL
287 add_charmap_undefined
($1);
292 ctype
: T_CTYPE T_NL ctype_list T_END T_CTYPE T_NL
296 | T_CTYPE T_NL copycat T_END T_CTYPE T_NL
299 ctype_list
: ctype_list ctype_kw
303 ctype_kw
: T_ISUPPER cc_list T_NL
304 | T_ISLOWER cc_list T_NL
305 | T_ISALPHA cc_list T_NL
306 | T_ISDIGIT cc_list T_NL
307 | T_ISPUNCT cc_list T_NL
308 | T_ISXDIGIT cc_list T_NL
309 | T_ISSPACE cc_list T_NL
310 | T_ISPRINT cc_list T_NL
311 | T_ISGRAPH cc_list T_NL
312 | T_ISBLANK cc_list T_NL
313 | T_ISCNTRL cc_list T_NL
314 | T_ISALNUM cc_list T_NL
315 | T_ISSPECIAL cc_list T_NL
316 | T_ISENGLISH cc_list T_NL
317 | T_ISNUMBER cc_list T_NL
318 | T_ISIDEOGRAM cc_list T_NL
319 | T_ISPHONOGRAM cc_list T_NL
320 | T_TOUPPER conv_list T_NL
321 | T_TOLOWER conv_list T_NL
324 cc_list
: cc_list T_SEMI cc_range_end
325 | cc_list T_SEMI cc_char
329 cc_range_end
: T_ELLIPSIS T_SEMI T_CHAR
341 add_charmap_undefined
($1);
345 conv_list
: conv_list T_SEMI conv_pair
350 conv_pair
: T_LPAREN T_CHAR T_COMMA T_CHAR T_RPAREN
352 add_caseconv
($2, $4);
354 | T_LPAREN T_SYMBOL T_COMMA T_CHAR T_RPAREN
356 add_charmap_undefined
($2);
358 | T_LPAREN T_SYMBOL T_COMMA T_SYMBOL T_RPAREN
360 add_charmap_undefined
($2);
361 add_charmap_undefined
($4);
363 | T_LPAREN T_CHAR T_COMMA T_SYMBOL T_RPAREN
365 add_charmap_undefined
($4);
369 collate
: T_COLLATE T_NL coll_order T_END T_COLLATE T_NL
373 | T_COLLATE T_NL coll_optional coll_order T_END T_COLLATE T_NL
377 | T_COLLATE T_NL copycat T_END T_COLLATE T_NL
381 coll_optional
: coll_optional coll_symbols
382 | coll_optional coll_elements
388 coll_symbols
: T_COLLATING_SYMBOL T_SYMBOL T_NL
395 coll_elements
: T_COLLATING_ELEMENT T_SYMBOL T_FROM
string T_NL
397 define_collelem
($2, get_wcs
());
401 coll_order
: T_ORDER_START T_NL order_list T_ORDER_END T_NL
403 /* If no order list supplied default to one forward */
404 add_order_bit
(T_FORWARD
);
405 add_order_directive
();
407 | T_ORDER_START order_args T_NL order_list T_ORDER_END T_NL
411 order_args
: order_args T_SEMI order_arg
413 add_order_directive
();
417 add_order_directive
();
421 order_arg
: order_arg T_COMMA order_dir
425 order_dir
: T_FORWARD
427 add_order_bit
(T_FORWARD
);
431 add_order_bit
(T_BACKWARD
);
435 add_order_bit
(T_POSITION
);
439 order_list
: order_list order_item
443 order_item
: T_COLLSYM T_NL
445 end_order_collsym
($1);
451 | order_itemkw order_weights T_NL
457 order_itemkw
: T_CHAR
459 start_order_char
($1);
463 start_order_ellipsis
();
467 start_order_collelem
($1);
471 start_order_undefined
();
475 start_order_symbol
($1);
479 order_weights
: order_weights T_SEMI order_weight
480 | order_weights T_SEMI
484 order_weight
: T_COLLELEM
486 add_order_collelem
($1);
490 add_order_collsym
($1);
498 add_order_ellipsis
();
506 add_order_symbol
($1);
508 | T_QUOTE order_str T_QUOTE
514 order_str
: order_str order_stritem
518 order_stritem
: T_CHAR
524 add_subst_collsym
($1);
528 add_subst_collelem
($1);
532 add_subst_symbol
($1);
536 messages
: T_MESSAGES T_NL messages_list T_END T_MESSAGES T_NL
540 | T_MESSAGES T_NL copycat T_END T_MESSAGES T_NL
543 messages_list
: messages_list messages_item
547 messages_kw
: T_YESSTR
553 messages_item
: messages_kw
string T_NL
555 add_message
(get_wcs
());
559 monetary
: T_MONETARY T_NL monetary_list T_END T_MONETARY T_NL
563 | T_MONETARY T_NL copycat T_END T_MONETARY T_NL
566 monetary_list
: monetary_list monetary_kw
570 monetary_strkw
: T_INT_CURR_SYMBOL
572 | T_MON_DECIMAL_POINT
573 | T_MON_THOUSANDS_SEP
578 monetary_numkw
: T_INT_FRAC_DIGITS
586 | T_INT_P_CS_PRECEDES
587 | T_INT_N_CS_PRECEDES
588 | T_INT_P_SEP_BY_SPACE
589 | T_INT_N_SEP_BY_SPACE
594 monetary_kw
: monetary_strkw
string T_NL
596 add_monetary_str
(get_wcs
());
598 | monetary_numkw T_NUMBER T_NL
600 add_monetary_num
($2);
602 | T_MON_GROUPING mon_group_list T_NL
605 mon_group_list
: T_NUMBER
607 reset_monetary_group
();
608 add_monetary_group
($1);
610 | mon_group_list T_SEMI T_NUMBER
612 add_monetary_group
($3);
617 numeric
: T_NUMERIC T_NL numeric_list T_END T_NUMERIC T_NL
621 | T_NUMERIC T_NL copycat T_END T_NUMERIC T_NL
625 numeric_list
: numeric_list numeric_item
630 numeric_item
: numeric_strkw
string T_NL
632 add_numeric_str
(get_wcs
());
634 | T_GROUPING group_list T_NL
637 numeric_strkw
: T_DECIMAL_POINT
642 group_list
: T_NUMBER
644 reset_numeric_group
();
645 add_numeric_group
($1);
647 | group_list T_SEMI T_NUMBER
649 add_numeric_group
($3);
654 time
: T_TIME T_NL time_kwlist T_END T_TIME T_NL
658 | T_TIME T_NL copycat T_END T_NUMERIC T_NL
661 time_kwlist
: time_kwlist time_kw
665 time_kw
: time_strkw
string T_NL
667 add_time_str
(get_wcs
());
669 | time_listkw time_list T_NL
675 time_listkw
: T_ABDAY
684 time_strkw
: T_ERA_D_T_FMT
694 time_list
: time_list T_SEMI
string
696 add_time_list
(get_wcs
());
701 add_time_list
(get_wcs
());