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 2011 Nexenta Systems, Inc.  All rights reserved.
  15  */
  16 
  17 /*
  18  * POSIX iconv charmap grammar.
  19  */
  20 
  21 #include <wchar.h>
  22 #include <stdio.h>
  23 #include <limits.h>
  24 #include "charmap.h"
  25 
  26 %}
  27 %union {
  28         char            *token;
  29         int             num;
  30         char            mbs[MB_LEN_MAX + 2]; /* NB: [0] is length! */
  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_END
  49 %token          T_CHARMAP
  50 %token          T_WIDTH
  51 %token          T_WIDTH_DEFAULT
  52 %token  <mbs>             T_CHAR
  53 %token  <token>           T_NAME
  54 %token  <num>             T_NUMBER
  55 %token  <token>           T_SYMBOL
  56 
  57 %%
  58 
  59 goal            : setting_list charmap
  60                 | charmap
  61                 ;
  62 
  63 string          : T_QUOTE charlist T_QUOTE
  64                 | T_QUOTE T_QUOTE
  65                 ;
  66 
  67 charlist        : charlist T_CHAR
  68                 | T_CHAR
  69                 ;
  70 
  71 setting_list    : setting_list setting
  72                 | setting
  73                 ;
  74 
  75 setting         : T_COM_CHAR T_CHAR T_NL
  76                 {
  77                         com_char = $2[1];
  78                 }
  79                 | T_ESC_CHAR T_CHAR T_NL
  80                 {
  81                         esc_char = $2[1];
  82                 }
  83                 | T_MB_CUR_MAX T_NUMBER T_NL
  84                 {
  85                         mb_cur_max = $2;
  86                 }
  87                 | T_MB_CUR_MIN T_NUMBER T_NL
  88                 {
  89                         mb_cur_min = $2;
  90                 }
  91                 | T_CODE_SET string T_NL
  92                 {
  93                         /* ignore */
  94                 }
  95                 ;
  96 
  97 charmap         : T_CHARMAP T_NL charmap_list T_END T_CHARMAP T_NL
  98 
  99 charmap_list    : charmap_list charmap_entry
 100                 | charmap_entry
 101                 ;
 102 
 103 charmap_entry   : T_SYMBOL T_CHAR
 104                 {
 105                         add_charmap($1, $2);
 106                         scan_to_eol();
 107                 }
 108                 | T_SYMBOL T_ELLIPSIS T_SYMBOL T_CHAR
 109                 {
 110                         add_charmap_range($1, $3, $4);
 111                         scan_to_eol();
 112                 }
 113                 | T_NL
 114                 ;