0001 /**
0002 * @brief Tuxedo ubb config lexer
0003 *
0004 * @file ubb.l
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 %option prefix="ubb"
0035 %option noyywrap nodefault yylineno
0036 /* Context for reading field */
0037 %x STRING
0038
0039 %{
0040 #include <ndebug.h>
0041 #include <stdlib.h>
0042 #include <string.h>
0043 #include <nstdutil.h>
0044 #include "ubb.h"
0045 #include "ubb.tab.h"
0046 /* Handle locations */
0047 int ndrx_G_ubbcolumn = 1;
0048 int ndrx_G_ubbline = 1;
0049 #define YY_USER_ACTION ubblloc.first_column = ndrx_G_ubbcolumn; ubblloc.last_column = ndrx_G_ubbcolumn+ubbleng-1; \
0050 ndrx_G_ubbcolumn +=ubbleng;
0051
0052 %}
0053
0054 %%
0055
0056
0057 ^[ \t\r]*#.*$ {
0058 }
0059
0060 [ \t\r]+ {
0061 }
0062 #.*$ {
0063 }
0064 "DEFAULT:" {
0065
0066 ubblval.val = NDRX_STRDUP("DEFAULT:");
0067 if (NULL==ubblval.val)
0068 {
0069 ubberror("Failed to copy string - OOM?");
0070 return EOL;
0071 }
0072 return DEFAULT;
0073 }
0074
0075 "=" {
0076 return EQUAL;
0077 }
0078
0079 "," {
0080 return COMMA;
0081 }
0082
0083 "*RESOURCES" {
0084 return RESOURCES;
0085 }
0086
0087 \*[A-Za-z0-9]+ {
0088 ubblval.val = NDRX_STRDUP(ubbtext);
0089 if (NULL==ubblval.val)
0090 {
0091 ubberror("Failed to copy string - OOM?");
0092 return EOL;
0093 }
0094 return SECTION;
0095 }
0096
0097 [A-Za-z0-9_]+ {
0098 ubblval.val = NDRX_STRDUP(ubbtext);
0099 if (NULL==ubblval.val)
0100 {
0101 ubberror("Failed to copy string - OOM?");
0102 return EOL;
0103 }
0104 return OPTION;
0105 }
0106
0107 "\"" {
0108 BEGIN STRING;
0109 ndrx_growlist_free(&ndrx_G_ubbp.stringbuffer);
0110 }
0111
0112 <STRING>\\\\ {
0113 char c='\\';
0114 if (EXSUCCEED!=ndrx_growlist_append(&ndrx_G_ubbp.stringbuffer, &c))
0115 {
0116 ubberror("Failed to append text to string buffer");
0117 return EOL;
0118 }
0119 }
0120
0121 <STRING>\\\" {
0122 char c='\"';
0123 if (EXSUCCEED!=ndrx_growlist_append(&ndrx_G_ubbp.stringbuffer, &c))
0124 {
0125 ubberror("Failed to append text to string buffer");
0126 return EOL;
0127 }
0128 }
0129
0130 <STRING>[^\n\"] {
0131 /* add string, char by char? */
0132 if (EXSUCCEED!=ndrx_growlist_append(&ndrx_G_ubbp.stringbuffer, ubbtext))
0133 {
0134 ubberror("Failed to append text to string buffer");
0135 return EOL;
0136 }
0137 }
0138
0139 <STRING>\n {
0140 /* add string, char by char? */
0141 if (EXSUCCEED!=ndrx_growlist_append(&ndrx_G_ubbp.stringbuffer, ubbtext))
0142 {
0143 ubberror("Failed to append text to string buffer");
0144 return EOL;
0145 }
0146 ndrx_G_ubbline++;
0147 }
0148
0149 <STRING>\" {
0150 char c='\0';
0151 if (EXSUCCEED!=ndrx_growlist_append(&ndrx_G_ubbp.stringbuffer, &c))
0152 {
0153 ubberror("Failed to append text to string buffer");
0154 return EOL;
0155 }
0156 ubblval.val=NDRX_STRDUP(ndrx_G_ubbp.stringbuffer.mem);
0157 BEGIN INITIAL;
0158 return OPTION;
0159 }
0160
0161 [ \t\r] {
0162 }
0163
0164 [ \n] {
0165 /* count the lines for the error */
0166 ndrx_G_ubbline++;
0167 }
0168
0169 . {
0170 ubberror("Invalid character [%s]", ubbtext);
0171 return EOL;
0172 }
0173
0174 %%
0175
0176 /* . { printf("lex Unknown character = '%s'\n", ddrtext); ddrerror("lex Unknown character"); }*/
0177
0178 /* yylex_destroy() is missing on older bison versions */
0179 #if !defined(TUX_FLEX_MAJOR_VERSION) || TUX_FLEX_MAJOR_VERSION < 2 \
0180 || (TUX_FLEX_MAJOR_VERSION == 2 \
0181 && (!defined(TUX_FLEX_MINOR_VERSION) || TUX_FLEX_MINOR_VERSION < 5 \
0182 || (TUX_FLEX_MINOR_VERSION == 5 \
0183 && (!defined(TUX_FLEX_SUBMINOR_VERSION) \
0184 || TUX_FLEX_SUBMINOR_VERSION < 9))))
0185
0186 #define ubblex_destroy() ubb_delete_buffer(YY_CURRENT_BUFFER)
0187
0188 #endif
0189
0190
0191 /* vim: set ts=4 sw=4 et smartindent: */