0001 /**
0002 * @brief Tokenize the range string
0003 * We will use one additional global for string buffer
0004 *
0005 *
0006 * @file ddr_range.l
0007 */
0008 /* -----------------------------------------------------------------------------
0009 * Enduro/X Middleware Platform for Distributed Transaction Processing
0010 * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0011 * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0012 * This software is released under one of the following licenses:
0013 * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0014 * See LICENSE file for full text.
0015 * -----------------------------------------------------------------------------
0016 * AGPL license:
0017 *
0018 * This program is free software; you can redistribute it and/or modify it under
0019 * the terms of the GNU Affero General Public License, version 3 as published
0020 * by the Free Software Foundation;
0021 *
0022 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0023 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0024 * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0025 * for more details.
0026 *
0027 * You should have received a copy of the GNU Affero General Public License along
0028 * with this program; if not, write to the Free Software Foundation, Inc.,
0029 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0030 *
0031 * -----------------------------------------------------------------------------
0032 * A commercial use license is available from Mavimax, Ltd
0033 * contact@mavimax.com
0034 * -----------------------------------------------------------------------------
0035 */
0036 %option prefix="ddr"
0037 %option noyywrap nodefault yylineno
0038 /* Context for reading field */
0039 %x STRING
0040
0041 %{
0042 #include <ndebug.h>
0043 #include <stdlib.h>
0044 #include <string.h>
0045 #include <nstdutil.h>
0046
0047 #ifdef NDRX_TMLOADCF
0048 /* we are building converter */
0049 #include "ubb.h"
0050 #include "ddr.tab.h"
0051 #else
0052 #include <ndrx_ddr.h>
0053 #include <ndrxd.h>
0054 #include "expr_range.tab.h"
0055 #endif
0056
0057 /* Handle locations */
0058 int ndrx_G_ddrcolumn = 1;
0059 #define YY_USER_ACTION ddrlloc.first_column = ndrx_G_ddrcolumn; ddrlloc.last_column = ndrx_G_ddrcolumn+ddrleng-1; \
0060 ndrx_G_ddrcolumn +=ddrleng;
0061
0062 %}
0063
0064 %%
0065 "MIN" {
0066 return MIN;
0067 }
0068 "MAX" {
0069 return MAX;
0070 }
0071 "*" {
0072 return DEFAULT;
0073 }
0074 "-" {
0075 return MINUS;
0076 }
0077 ":" {
0078 return COLON;
0079 }
0080 "," {
0081 return COMMA;
0082 }
0083 [^\*\-:,\n\t \']+ {
0084 ddrlval.val = NDRX_STRDUP(ddrtext);
0085 if (NULL==ddrlval.val)
0086 {
0087 ddrerror("Failed to copy string - OOM?");
0088 return EOL;
0089 }
0090 return RANGEVAL;
0091 }
0092 "'" {
0093 BEGIN STRING;
0094 ndrx_growlist_free(&ndrx_G_ddrp.stringbuffer);
0095 }
0096 <STRING>\\\\ {
0097 char c='\\';
0098 if (EXSUCCEED!=ndrx_growlist_append(&ndrx_G_ddrp.stringbuffer, &c))
0099 {
0100 ddrerror("Failed to append text to string buffer");
0101 return EOL;
0102 }
0103 }
0104 <STRING>\\' {
0105 char c='\'';
0106 if (EXSUCCEED!=ndrx_growlist_append(&ndrx_G_ddrp.stringbuffer, &c))
0107 {
0108 ddrerror("Failed to append text to string buffer");
0109 return EOL;
0110 }
0111 }
0112 <STRING>[^'] {
0113 /* add string */
0114 if (EXSUCCEED!=ndrx_growlist_append(&ndrx_G_ddrp.stringbuffer, ddrtext))
0115 {
0116 ddrerror("Failed to append text to string buffer");
0117 return EOL;
0118 }
0119 }
0120 <STRING>' {
0121 char c='\0';
0122 if (EXSUCCEED!=ndrx_growlist_append(&ndrx_G_ddrp.stringbuffer, &c))
0123 {
0124 ddrerror("Failed to append text to string buffer");
0125 return EOL;
0126 }
0127
0128 BEGIN INITIAL;
0129 return STRVAL;
0130 }
0131 [ \t \n] {
0132 }
0133
0134 %%
0135
0136 /* yylex_destroy() is missing on older bison versions */
0137 #if !defined(DDR_FLEX_MAJOR_VERSION) || DDR_FLEX_MAJOR_VERSION < 2 \
0138 || (DDR_FLEX_MAJOR_VERSION == 2 \
0139 && (!defined(DDR_FLEX_MINOR_VERSION) || DDR_FLEX_MINOR_VERSION < 5 \
0140 || (DDR_FLEX_MINOR_VERSION == 5 \
0141 && (!defined(DDR_FLEX_SUBMINOR_VERSION) \
0142 || DDR_FLEX_SUBMINOR_VERSION < 9))))
0143
0144 #define ddrlex_destroy() ddr_delete_buffer(YY_CURRENT_BUFFER)
0145
0146 #endif
0147
0148
0149 /* vim: set ts=4 sw=4 et smartindent: */