1 /*********************************************************************************************************
2  * Software License Agreement (BSD License)                                                               *
3  * Author: Thomas Klausner <tk@giga.or.at>                                                                *
4  *                                                                                                        *
5  * Copyright (c) 2018, Thomas Klausner                                                                    *
6  * All rights reserved.                                                                                   *
7  *                                                                                                        *
8  * Written under contract by Effortel Technologies SA, http://effortel.com/                               *
9  *                                                                                                        *
10  * Redistribution and use of this software in source and binary forms, with or without modification, are  *
11  * permitted provided that the following conditions are met:                                              *
12  *                                                                                                        *
13  * * Redistributions of source code must retain the above                                                 *
14  *   copyright notice, this list of conditions and the                                                    *
15  *   following disclaimer.                                                                                *
16  *                                                                                                        *
17  * * Redistributions in binary form must reproduce the above                                              *
18  *   copyright notice, this list of conditions and the                                                    *
19  *   following disclaimer in the documentation and/or other                                               *
20  *   materials provided with the distribution.                                                            *
21  *                                                                                                        *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
24  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
25  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT     *
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS    *
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
28  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                                             *
30  *********************************************************************************************************/
31 
32 /* Tokenizer
33  *
34  */
35 
36 %{
37 #include "rt_rewrite.h"
38 /* Include yacc tokens definitions */
39 #include "rt_rewrite_conf.tab.h"
40 
41 /* Update the column information */
42 #define YY_USER_ACTION { 						\
43 	yylloc->first_column = yylloc->last_column + 1; 		\
44 	yylloc->last_column = yylloc->first_column + yyleng - 1;	\
45 }
46 
47 /* Avoid warning with newer flex */
48 #define YY_NO_INPUT
49 
50 %}
51 
52 qstring		\"[^\"\n]*\"
53 
54 
55 %option bison-bridge bison-locations
56 %option noyywrap
57 %option nounput
58 
59 %%
60 
61 	/* Update the line count */
62 \n			{
63 				yylloc->first_line++;
64 				yylloc->last_line++;
65 				yylloc->last_column=0;
66 			}
67 
68 	/* Eat all spaces but not new lines */
69 ([[:space:]]{-}[\n])+	;
70 	/* Eat all comments */
71 #.*$			;
72 
73 
74 	/* Recognize quoted strings */
75 {qstring}		{
76 				/* Match a quoted string. */
77 				CHECK_MALLOC_DO( yylval->string = strdup(yytext+1),
78 				{
79 					TRACE_DEBUG(INFO, "Unable to copy the string '%s': %s", yytext, strerror(errno));
80 					return LEX_ERROR; /* trig an error in yacc parser */
81 				} );
82 				yylval->string[strlen(yytext) - 2] = '\0';
83 				return QSTRING;
84 			}
85 
86 
87 	/* The key words */
88 (?i:MAP)	 	{	return MAP;	}
89 (?i:DROP)	 	{	return DROP;	}
90 
91 	/* Valid single characters for yyparse */
92 [=:;>]			{ return yytext[0]; }
93 
94 	/* Unrecognized sequence, if it did not match any previous pattern */
95 [^[:space:]\":=>;\n]+	{
96 				fd_log_debug("Unrecognized text on line %d col %d: '%s'.", yylloc->first_line, yylloc->first_column, yytext);
97 			 	return LEX_ERROR;
98 			}
99 
100 %%
101