0001 /**
0002 * @brief DDR routing range parser
0003 *
0004 * @file ddr_range.y
0005 */
0006 /* -----------------------------------------------------------------------------
0007 * Enduro/X Middleware Platform for Distributed Transaction Processing
0008 * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009 * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010 * This software is released under one of the following licenses:
0011 * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012 * See LICENSE file for full text.
0013 * -----------------------------------------------------------------------------
0014 * AGPL license:
0015 *
0016 * This program is free software; you can redistribute it and/or modify it under
0017 * the terms of the GNU Affero General Public License, version 3 as published
0018 * by the Free Software Foundation;
0019 *
0020 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022 * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023 * for more details.
0024 *
0025 * You should have received a copy of the GNU Affero General Public License along
0026 * with this program; if not, write to the Free Software Foundation, Inc.,
0027 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028 *
0029 * -----------------------------------------------------------------------------
0030 * A commercial use license is available from Mavimax, Ltd
0031 * contact@mavimax.com
0032 * -----------------------------------------------------------------------------
0033 */
0034
0035 /* %define api.prefix {ddr}*/
0036 %name-prefix "ddr"
0037
0038 %{
0039 #include <stdio.h>
0040 #include <stdlib.h>
0041 #include <ndebug.h>
0042
0043 #ifdef NDRX_TMLOADCF
0044 #include "ubb.h"
0045 #else
0046 #include <ndrxd.h>
0047 #include <ndrx_ddr.h>
0048 #endif
0049
0050 extern int ddrlex (void);
0051 %}
0052
0053 %union {
0054 char *val;
0055 ndrx_routcritseq_dl_t *rts;
0056 }
0057
0058 /* declare tokens */
0059 %token EOL
0060 %token MINUS /**< min/max split */
0061 %token COLON /**< group after */
0062 %token COMMA /**< new ranage */
0063 %token MIN /**< min value, flag */
0064 %token MAX /**< max value, flag */
0065 %token DEFAULT /**< default symbol */
0066 %token <val> RANGEVAL /*< range value, no quotes */
0067 %token STRVAL /*< string value with quotes */
0068
0069 %start group_expr_loop
0070
0071 %type <val> range_val
0072 %type <rts> range_expr
0073
0074
0075 %destructor { NDRX_FREE($$); } <*>
0076
0077 %locations
0078
0079 %%
0080
0081 /*
0082 * Note that %% and !% works only for string vs string or field vs string.
0083 */
0084
0085
0086 group_expression:
0087 range_expr COLON range_val { if (ndrx_G_ddrp.error || EXSUCCEED!=ndrx_ddr_add_group($1, $3, EXTRUE)) {YYERROR;} }
0088 | range_expr COLON DEFAULT { if (ndrx_G_ddrp.error || EXSUCCEED!=ndrx_ddr_add_group($1, NULL, EXFALSE)) {YYERROR;} }
0089 | range_expr COLON MIN { if (ndrx_G_ddrp.error || EXSUCCEED!=ndrx_ddr_add_group($1, "MIN", EXFALSE)) {YYERROR;} }
0090 | range_expr COLON MAX { if (ndrx_G_ddrp.error || EXSUCCEED!=ndrx_ddr_add_group($1, "MAX", EXFALSE)) {YYERROR;} }
0091 ;
0092
0093 /* get the range variants */
0094 range_expr:
0095 range_val MINUS range_val { $$ = ndrx_ddr_new_rangeexpr($1, $3); if (!$$|| ndrx_G_ddrp.error) {YYERROR;}}
0096 | MIN MINUS range_val { $$ = ndrx_ddr_new_rangeexpr(NULL, $3); if (!$$|| ndrx_G_ddrp.error) {YYERROR;}}
0097 | MIN MINUS MAX { $$ = ndrx_ddr_new_rangeexpr(NULL, NULL);if (!$$|| ndrx_G_ddrp.error) {YYERROR;}}
0098 | range_val MINUS MAX { $$ = ndrx_ddr_new_rangeexpr($1, NULL); if (!$$|| ndrx_G_ddrp.error) {YYERROR;}}
0099 | range_val { $$ = ndrx_ddr_new_rangeexpr($1, $1); if (!$$|| ndrx_G_ddrp.error) {YYERROR;}}
0100 | DEFAULT { $$ = ndrx_ddr_new_rangeexpr(NULL, NULL);if (!$$|| ndrx_G_ddrp.error) {YYERROR;}}
0101 ;
0102 /* get the range variants val */
0103 range_val:
0104 RANGEVAL {$$ = ndrx_ddr_new_rangeval($1, 0, EXTRUE); if (!$$|| ndrx_G_ddrp.error) {YYERROR; }}
0105 | MINUS RANGEVAL {$$ = ndrx_ddr_new_rangeval($2, EXTRUE, EXTRUE); if (!$$|| ndrx_G_ddrp.error) {YYERROR; }}
0106 | STRVAL {$$ = ndrx_ddr_new_rangeval(ndrx_G_ddrp.stringbuffer.mem, 0, EXFALSE); if (!$$|| ndrx_G_ddrp.error) {YYERROR; }}
0107 ;
0108
0109
0110 group_expr_loop:
0111 group_expression
0112 | group_expr_loop COMMA group_expression
0113 | group_expr_loop EOL
0114 ;
0115
0116 %%
0117
0118 /* vim: set ts=4 sw=4 et smartindent: */