1 %{
   2 /*
   3  * This file and its contents are supplied under the terms of the
   4  * Common Development and Distribution License ("CDDL"), version 1.0.
   5  * You may only use this file in accordance with the terms of version
   6  * 1.0 of the CDDL.
   7  *
   8  * A full copy of the text of the CDDL should have accompanied this
   9  * source.  A copy of the CDDL is also available via the Internet at
  10  * http://www.illumos.org/license/CDDL.
  11  */
  12 
  13 /*
  14  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
  15  */
  16 
  17 /*
  18  * POSIX charmap grammar.
  19  */
  20 
  21 #include <wchar.h>
  22 #include <stdio.h>
  23 #include <limits.h>
  24 #include "iconv.h"
  25 
  26 %}
  27 %union {
  28         int             num;
  29         wchar_t         wc;
  30         char            *token;
  31 }
  32 
  33 %token          T_CODE_SET
  34 %token          T_MB_CUR_MAX
  35 %token          T_MB_CUR_MIN
  36 %token          T_COM_CHAR
  37 %token          T_ESC_CHAR
  38 %token          T_LT
  39 %token          T_GT
  40 %token          T_NL
  41 %token          T_SEMI
  42 %token          T_COMMA
  43 %token          T_ELLIPSIS
  44 %token          T_RPAREN
  45 %token          T_LPAREN
  46 %token          T_QUOTE
  47 %token          T_NULL
  48 %token          T_WS
  49 %token          T_END
  50 %token          T_COPY
  51 %token          T_CHARMAP
  52 %token          T_WIDTH
  53 %token          T_WIDTH_DEFAULT
  54 %token  <wc>              T_CHAR
  55 %token  <token>           T_NAME
  56 %token  <num>             T_NUMBER
  57 %token  <token>           T_SYMBOL
  58 
  59 %%
  60 
  61 iconv           : setting_list categories
  62                 | categories
  63                 ;
  64 
  65 
  66 setting_list    : setting_list setting
  67                 | setting
  68                 ;
  69 
  70 setting         : T_COM_CHAR T_CHAR T_NL
  71                 {
  72                         printf("SEtting comment\n");
  73                         com_char = $2;
  74                 }
  75                 | T_ESC_CHAR T_CHAR T_NL
  76                 {
  77                         esc_char = $2;
  78                 }
  79                 | T_MB_CUR_MAX T_NUMBER T_NL
  80                 {
  81                         mb_cur_max = $2;
  82                 }
  83                 | T_MB_CUR_MIN T_NUMBER T_NL
  84                 {
  85                         mb_cur_min = $2;
  86                 }
  87                 | T_CODE_SET string T_NL
  88                 {
  89                         wchar_t *w = get_wcs();
  90 
  91                         set_wide_encoding(to_mb_string(w));
  92                         free(w);
  93                 }
  94                 | T_CODE_SET T_NAME T_NL
  95                 {
  96                         set_wide_encoding($2);
  97                 }
  98                 ;
  99 
 100 categories      : categories category
 101                 | category
 102                 ;
 103 
 104 category        : charmap
 105                 | width
 106                 ;
 107 
 108 charmap         : T_CHARMAP T_NL charmap_list T_END T_CHARMAP T_NL
 109 
 110 charmap_list    : charmap_list charmap_entry
 111                 | charmap_entry
 112                 ;
 113 
 114 charmap_entry   : T_SYMBOL T_CHAR
 115                 {
 116                         add_charmap($1, $2);
 117                         scan_to_eol();
 118                 }
 119                 | T_SYMBOL T_ELLIPSIS T_SYMBOL T_CHAR
 120                 {
 121                         add_charmap_range($1, $3, $4);
 122                         scan_to_eol();
 123                 }
 124                 | T_NL
 125                 ;
 126 
 127 width           : T_WIDTH T_NL width_list T_END T_WIDTH T_NL
 128 
 129 width_list      : width_list width_entry
 130                 | width_entry
 131                 ;
 132 
 133 width_entry     : T_SYMBOL T_NUMBER
 134                 {
 135                         printf("WIDTH ENTRY\n");
 136                 }
 137                 | T_SYMBOL T_ELLIPSIS T_SYMBOL T_NUMBER
 138                 {
 139                         printf("WIDTH ENTY ELL\n");
 140                 }
 141                 | T_NL
 142                 ;
 143 
 144 string          : T_QUOTE charlist T_QUOTE
 145                 | T_QUOTE T_QUOTE
 146                 ;
 147 
 148 charlist        : charlist T_CHAR
 149                 {
 150                         add_wcs($2);
 151                 }
 152                 | T_CHAR
 153                 {
 154                         add_wcs($1);
 155                 }
 156                 ;