2012-05-31 08:45:02 +02:00
|
|
|
%{
|
2012-05-31 16:04:51 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2012-09-07 10:27:31 +02:00
|
|
|
#include "i2-config.h"
|
2012-05-31 09:43:46 +02:00
|
|
|
#include "config_parser.h"
|
2012-05-31 09:14:44 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
2012-05-31 08:45:02 +02:00
|
|
|
|
2012-06-06 14:38:28 +02:00
|
|
|
#define YY_EXTRA_TYPE ConfigCompiler *
|
|
|
|
#define YY_USER_ACTION \
|
|
|
|
do { \
|
2012-07-08 21:33:51 +02:00
|
|
|
yylloc->Path = yyextra->GetPath(); \
|
2012-06-06 14:38:28 +02:00
|
|
|
yylloc->FirstLine = yylineno; \
|
|
|
|
yylloc->FirstColumn = yycolumn; \
|
|
|
|
yylloc->LastLine = yylineno; \
|
|
|
|
yylloc->LastColumn = yycolumn + yyleng - 1; \
|
|
|
|
yycolumn += yyleng; \
|
|
|
|
} while (0);
|
2012-05-31 08:45:02 +02:00
|
|
|
|
2012-05-31 09:43:46 +02:00
|
|
|
#define YY_INPUT(buf, result, max_size) \
|
|
|
|
do { \
|
|
|
|
result = yyextra->ReadInput(buf, max_size); \
|
2012-05-31 08:45:02 +02:00
|
|
|
} while (0)
|
|
|
|
%}
|
|
|
|
|
|
|
|
%option reentrant noyywrap yylineno
|
|
|
|
%option bison-bridge bison-locations
|
2012-05-31 09:14:44 +02:00
|
|
|
%option never-interactive nounistd
|
2012-05-31 08:45:02 +02:00
|
|
|
|
|
|
|
%x IN_C_COMMENT
|
|
|
|
|
|
|
|
%%
|
2013-02-02 14:28:11 +01:00
|
|
|
type return T_TYPE;
|
|
|
|
dictionary { yylval->type = TypeDictionary; return T_TYPE_DICTIONARY; }
|
|
|
|
number { yylval->type = TypeNumber; return T_TYPE_NUMBER; }
|
|
|
|
string { yylval->type = TypeString; return T_TYPE_STRING; }
|
|
|
|
scalar { yylval->type = TypeScalar; return T_TYPE_SCALAR; }
|
|
|
|
any { yylval->type = TypeAny; return T_TYPE_ANY; }
|
2013-02-06 00:32:05 +01:00
|
|
|
%validator { return T_VALIDATOR; }
|
|
|
|
%require { return T_REQUIRE; }
|
|
|
|
%attribute { return T_ATTRIBUTE; }
|
2012-05-31 16:04:51 +02:00
|
|
|
abstract return T_ABSTRACT;
|
|
|
|
local return T_LOCAL;
|
|
|
|
object return T_OBJECT;
|
2013-02-16 09:18:34 +01:00
|
|
|
template return T_TEMPLATE;
|
2012-08-03 14:13:39 +02:00
|
|
|
#include return T_INCLUDE;
|
2013-01-17 15:05:34 +01:00
|
|
|
#library return T_LIBRARY;
|
2012-05-31 16:04:51 +02:00
|
|
|
inherits return T_INHERITS;
|
2012-06-01 16:49:33 +02:00
|
|
|
null return T_NULL;
|
2013-02-02 14:28:11 +01:00
|
|
|
partial return T_PARTIAL;
|
2013-01-24 10:08:03 +01:00
|
|
|
true { yylval->num = 1; return T_NUMBER; }
|
|
|
|
false { yylval->num = 0; return T_NUMBER; }
|
2013-02-02 14:28:11 +01:00
|
|
|
[a-zA-Z_\*][:a-zA-Z0-9\-_\*]* { yylval->text = strdup(yytext); return T_IDENTIFIER; }
|
2012-07-08 21:24:20 +02:00
|
|
|
\"[^\"]*\" { yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING; }
|
2013-02-01 22:44:58 +01:00
|
|
|
\<[^\>]*\> { yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING_ANGLE; }
|
2013-02-08 10:14:24 +01:00
|
|
|
-?[0-9]+(\.[0-9]+)?ms { yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; }
|
2012-09-25 11:17:04 +02:00
|
|
|
-?[0-9]+(\.[0-9]+)?h { yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; }
|
|
|
|
-?[0-9]+(\.[0-9]+)?m { yylval->num = strtod(yytext, NULL) * 60; return T_NUMBER; }
|
|
|
|
-?[0-9]+(\.[0-9]+)?s { yylval->num = strtod(yytext, NULL); return T_NUMBER; }
|
2012-07-11 21:03:22 +02:00
|
|
|
-?[0-9]+(\.[0-9]+)? { yylval->num = strtod(yytext, NULL); return T_NUMBER; }
|
2012-05-31 16:04:51 +02:00
|
|
|
= { yylval->op = OperatorSet; return T_EQUAL; }
|
|
|
|
\+= { yylval->op = OperatorPlus; return T_PLUS_EQUAL; }
|
|
|
|
-= { yylval->op = OperatorMinus; return T_MINUS_EQUAL; }
|
|
|
|
\*= { yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; }
|
|
|
|
\/= { yylval->op = OperatorDivide; return T_DIVIDE_EQUAL; }
|
2012-05-31 08:45:02 +02:00
|
|
|
|
|
|
|
<INITIAL>{
|
2012-05-31 16:04:51 +02:00
|
|
|
"/*" BEGIN(IN_C_COMMENT);
|
2012-05-31 08:45:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
<IN_C_COMMENT>{
|
2012-05-31 16:04:51 +02:00
|
|
|
"*/" BEGIN(INITIAL);
|
|
|
|
[^*]+ /* ignore comment */
|
|
|
|
"*" /* ignore star */
|
2012-05-31 08:45:02 +02:00
|
|
|
}
|
|
|
|
|
2012-05-31 16:04:51 +02:00
|
|
|
\/\/[^\n]+ /* ignore C++-style comments */
|
2012-10-15 08:27:07 +02:00
|
|
|
[ \t\r\n]+ /* ignore whitespace */
|
2012-06-05 15:05:15 +02:00
|
|
|
|
|
|
|
. return yytext[0];
|
2012-05-31 08:45:02 +02:00
|
|
|
%%
|
|
|
|
|
|
|
|
|
2012-06-06 14:38:28 +02:00
|
|
|
void ConfigCompiler::InitializeScanner(void)
|
2012-05-31 08:45:02 +02:00
|
|
|
{
|
2012-05-31 09:43:46 +02:00
|
|
|
yylex_init(&m_Scanner);
|
|
|
|
yyset_extra(this, m_Scanner);
|
2012-05-31 08:45:02 +02:00
|
|
|
}
|
|
|
|
|
2012-06-06 14:38:28 +02:00
|
|
|
void ConfigCompiler::DestroyScanner(void)
|
2012-05-31 08:45:02 +02:00
|
|
|
{
|
2012-05-31 09:43:46 +02:00
|
|
|
yylex_destroy(m_Scanner);
|
2012-05-31 08:45:02 +02:00
|
|
|
}
|