2012-05-31 08:45:02 +02:00
|
|
|
%{
|
2012-05-31 16:04:51 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2015-01-22 12:00:23 +01:00
|
|
|
* Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
|
2012-05-31 16:04:51 +02:00
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "config/configcompiler.hpp"
|
2014-10-16 17:44:06 +02:00
|
|
|
#include "config/expression.hpp"
|
2014-11-30 23:32:13 +01:00
|
|
|
#include "base/exception.hpp"
|
2013-11-03 12:40:39 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-11-03 13:45:26 +01:00
|
|
|
#include "config/config_parser.hh"
|
2013-03-16 21:18:53 +01:00
|
|
|
#include <sstream>
|
2012-05-31 09:14:44 +02:00
|
|
|
|
2014-12-14 11:33:45 +01:00
|
|
|
#define YYLTYPE icinga::CompilerDebugInfo
|
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
|
2014-11-06 06:23:25 +01:00
|
|
|
%option noinput nounput
|
2012-05-31 08:45:02 +02:00
|
|
|
|
2013-02-16 19:12:56 +01:00
|
|
|
%x C_COMMENT
|
|
|
|
%x STRING
|
2013-02-16 22:49:13 +01:00
|
|
|
%x HEREDOC
|
2012-05-31 08:45:02 +02:00
|
|
|
|
|
|
|
%%
|
2014-12-16 06:18:39 +01:00
|
|
|
\" {
|
|
|
|
yyextra->m_LexBuffer.str("");
|
|
|
|
yyextra->m_LexBuffer.clear();
|
|
|
|
|
|
|
|
yyextra->m_LocationBegin = *yylloc;
|
|
|
|
|
|
|
|
BEGIN(STRING);
|
|
|
|
}
|
2013-02-16 19:12:56 +01:00
|
|
|
|
|
|
|
<STRING>\" {
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
|
2014-12-16 06:18:39 +01:00
|
|
|
yylloc->FirstLine = yyextra->m_LocationBegin.FirstLine;
|
|
|
|
yylloc->FirstColumn = yyextra->m_LocationBegin.FirstColumn;
|
|
|
|
|
2015-09-29 07:09:35 +02:00
|
|
|
yylval->text = new String(yyextra->m_LexBuffer.str());
|
2013-02-16 19:12:56 +01:00
|
|
|
|
|
|
|
return T_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
<STRING>\n {
|
2014-12-16 06:18:39 +01:00
|
|
|
BOOST_THROW_EXCEPTION(ScriptError("Unterminated string literal", DebugInfoRange(yyextra->m_LocationBegin, *yylloc)));
|
2013-02-16 19:12:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
<STRING>\\[0-7]{1,3} {
|
|
|
|
/* octal escape sequence */
|
|
|
|
int result;
|
|
|
|
|
|
|
|
(void) sscanf(yytext + 1, "%o", &result);
|
|
|
|
|
|
|
|
if (result > 0xff) {
|
|
|
|
/* error, constant is out-of-bounds */
|
2014-12-20 09:48:18 +01:00
|
|
|
BOOST_THROW_EXCEPTION(ScriptError("Constant is out of bounds: " + String(yytext), *yylloc));
|
2013-02-16 19:12:56 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 08:04:07 +01:00
|
|
|
yyextra->m_LexBuffer << static_cast<char>(result);
|
2013-02-16 19:12:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
<STRING>\\[0-9]+ {
|
|
|
|
/* generate error - bad escape sequence; something
|
|
|
|
* like '\48' or '\0777777'
|
|
|
|
*/
|
2014-12-20 09:48:18 +01:00
|
|
|
BOOST_THROW_EXCEPTION(ScriptError("Bad escape sequence found: " + String(yytext), *yylloc));
|
2013-02-16 19:12:56 +01:00
|
|
|
}
|
2014-11-27 08:04:07 +01:00
|
|
|
<STRING>\\n { yyextra->m_LexBuffer << "\n"; }
|
2015-01-07 08:56:52 +01:00
|
|
|
<STRING>\\\\ { yyextra->m_LexBuffer << "\\"; }
|
2015-01-07 13:06:02 +01:00
|
|
|
<STRING>\\\" { yyextra->m_LexBuffer << "\""; }
|
2014-11-27 08:04:07 +01:00
|
|
|
<STRING>\\t { yyextra->m_LexBuffer << "\t"; }
|
|
|
|
<STRING>\\r { yyextra->m_LexBuffer << "\r"; }
|
|
|
|
<STRING>\\b { yyextra->m_LexBuffer << "\b"; }
|
|
|
|
<STRING>\\f { yyextra->m_LexBuffer << "\f"; }
|
2014-12-20 09:48:18 +01:00
|
|
|
<STRING>\\\n { yyextra->m_LexBuffer << yytext[1]; }
|
|
|
|
<STRING>\\. {
|
|
|
|
BOOST_THROW_EXCEPTION(ScriptError("Bad escape sequence found: " + String(yytext), *yylloc));
|
|
|
|
}
|
2013-02-16 19:12:56 +01:00
|
|
|
|
|
|
|
<STRING>[^\\\n\"]+ {
|
|
|
|
char *yptr = yytext;
|
|
|
|
|
|
|
|
while (*yptr)
|
2014-11-27 08:04:07 +01:00
|
|
|
yyextra->m_LexBuffer << *yptr++;
|
2013-02-16 19:12:56 +01:00
|
|
|
}
|
|
|
|
|
2014-12-16 06:18:39 +01:00
|
|
|
<STRING><<EOF>> {
|
|
|
|
BOOST_THROW_EXCEPTION(ScriptError("End-of-file while in string literal", DebugInfoRange(yyextra->m_LocationBegin, *yylloc)));
|
|
|
|
}
|
2014-11-28 06:47:52 +01:00
|
|
|
|
2014-12-16 06:18:39 +01:00
|
|
|
\{\{\{ {
|
|
|
|
yyextra->m_LexBuffer.str("");
|
|
|
|
yyextra->m_LexBuffer.clear();
|
|
|
|
|
|
|
|
yyextra->m_LocationBegin = *yylloc;
|
|
|
|
|
|
|
|
BEGIN(HEREDOC);
|
|
|
|
}
|
2013-02-16 22:49:13 +01:00
|
|
|
|
|
|
|
<HEREDOC>\}\}\} {
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
|
2014-12-16 06:18:39 +01:00
|
|
|
yylloc->FirstLine = yyextra->m_LocationBegin.FirstLine;
|
|
|
|
yylloc->FirstColumn = yyextra->m_LocationBegin.FirstColumn;
|
|
|
|
|
2015-09-29 07:09:35 +02:00
|
|
|
yylval->text = new String(yyextra->m_LexBuffer.str());
|
2013-02-16 22:49:13 +01:00
|
|
|
|
|
|
|
return T_STRING;
|
|
|
|
}
|
|
|
|
|
2014-11-27 08:04:07 +01:00
|
|
|
<HEREDOC>(.|\n) { yyextra->m_LexBuffer << yytext[0]; }
|
2013-02-16 22:49:13 +01:00
|
|
|
|
2013-02-16 19:12:56 +01:00
|
|
|
<INITIAL>{
|
|
|
|
"/*" BEGIN(C_COMMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
<C_COMMENT>{
|
|
|
|
"*/" BEGIN(INITIAL);
|
2013-03-27 15:51:33 +01:00
|
|
|
[^*] /* ignore comment */
|
2013-02-16 19:12:56 +01:00
|
|
|
"*" /* ignore star */
|
|
|
|
}
|
|
|
|
|
2013-10-09 08:56:28 +02:00
|
|
|
<C_COMMENT><<EOF>> {
|
2014-12-18 16:55:45 +01:00
|
|
|
BOOST_THROW_EXCEPTION(ScriptError("End-of-file while in comment", *yylloc));
|
|
|
|
}
|
2013-10-09 08:56:28 +02:00
|
|
|
|
|
|
|
|
2013-02-24 01:10:34 +01:00
|
|
|
\/\/[^\n]* /* ignore C++-style comments */
|
2014-04-10 11:30:01 +02:00
|
|
|
#[^\n]* /* ignore shell-style comments */
|
2014-03-31 18:38:15 +02:00
|
|
|
[ \t] /* ignore whitespace */
|
2013-02-16 19:12:56 +01:00
|
|
|
|
|
|
|
<INITIAL>{
|
2012-05-31 16:04:51 +02:00
|
|
|
object return T_OBJECT;
|
2013-02-16 09:18:34 +01:00
|
|
|
template return T_TEMPLATE;
|
2013-03-21 14:30:28 +01:00
|
|
|
include return T_INCLUDE;
|
2013-11-29 10:39:48 +01:00
|
|
|
include_recursive return T_INCLUDE_RECURSIVE;
|
2015-10-07 15:09:55 +02:00
|
|
|
include_zones return T_INCLUDE_ZONES;
|
2013-03-21 14:30:28 +01:00
|
|
|
library return T_LIBRARY;
|
2012-06-01 16:49:33 +02:00
|
|
|
null return T_NULL;
|
2014-12-10 09:04:49 +01:00
|
|
|
true { yylval->boolean = 1; return T_BOOLEAN; }
|
|
|
|
false { yylval->boolean = 0; return T_BOOLEAN; }
|
2014-12-15 16:09:17 +01:00
|
|
|
const return T_CONST;
|
|
|
|
var return T_VAR;
|
2014-12-14 11:33:45 +01:00
|
|
|
this return T_THIS;
|
2015-01-16 13:04:34 +01:00
|
|
|
globals return T_GLOBALS;
|
|
|
|
locals return T_LOCALS;
|
2014-11-22 12:21:28 +01:00
|
|
|
use return T_USE;
|
2014-03-18 11:44:09 +01:00
|
|
|
apply return T_APPLY;
|
2014-04-05 12:56:56 +02:00
|
|
|
to return T_TO;
|
2014-03-18 11:44:09 +01:00
|
|
|
where return T_WHERE;
|
2014-03-27 12:30:24 +01:00
|
|
|
import return T_IMPORT;
|
2014-03-28 13:25:40 +01:00
|
|
|
assign return T_ASSIGN;
|
|
|
|
ignore return T_IGNORE;
|
2014-12-11 13:12:35 +01:00
|
|
|
function return T_FUNCTION;
|
|
|
|
return return T_RETURN;
|
2015-02-19 12:57:52 +01:00
|
|
|
break return T_BREAK;
|
|
|
|
continue return T_CONTINUE;
|
2014-12-11 13:12:35 +01:00
|
|
|
for return T_FOR;
|
|
|
|
if return T_IF;
|
|
|
|
else return T_ELSE;
|
2015-01-23 15:54:27 +01:00
|
|
|
while return T_WHILE;
|
2015-08-24 11:04:26 +02:00
|
|
|
throw return T_THROW;
|
2015-10-05 12:44:11 +02:00
|
|
|
ignore_on_error return T_IGNORE_ON_ERROR;
|
2015-11-03 16:34:34 +01:00
|
|
|
current_filename return T_CURRENT_FILENAME;
|
|
|
|
current_line return T_CURRENT_LINE;
|
2015-11-05 14:29:45 +01:00
|
|
|
debugger return T_DEBUGGER;
|
2014-11-04 11:01:00 +01:00
|
|
|
=\> return T_FOLLOWS;
|
2014-11-09 19:48:28 +01:00
|
|
|
\<\< return T_SHIFT_LEFT;
|
|
|
|
\>\> return T_SHIFT_RIGHT;
|
|
|
|
\<= return T_LESS_THAN_OR_EQUAL;
|
|
|
|
\>= return T_GREATER_THAN_OR_EQUAL;
|
|
|
|
== return T_EQUAL;
|
|
|
|
!= return T_NOT_EQUAL;
|
|
|
|
!in return T_NOT_IN;
|
|
|
|
in return T_IN;
|
|
|
|
&& return T_LOGICAL_AND;
|
|
|
|
\|\| return T_LOGICAL_OR;
|
2015-01-30 09:49:57 +01:00
|
|
|
\{\{ return T_NULLARY_LAMBDA_BEGIN;
|
|
|
|
\}\} return T_NULLARY_LAMBDA_END;
|
2015-09-29 07:09:35 +02:00
|
|
|
[a-zA-Z_][a-zA-Z0-9\_]* { yylval->text = new String(yytext); return T_IDENTIFIER; }
|
|
|
|
@[a-zA-Z_][a-zA-Z0-9\_]* { yylval->text = new String(yytext + 1); return T_IDENTIFIER; }
|
|
|
|
\<[^ \>]*\> { yytext[yyleng-1] = '\0'; yylval->text = new String(yytext + 1); return T_STRING_ANGLE; }
|
2014-11-23 23:19:46 +01:00
|
|
|
[0-9]+(\.[0-9]+)?ms { yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; }
|
|
|
|
[0-9]+(\.[0-9]+)?d { yylval->num = strtod(yytext, NULL) * 60 * 60 * 24; return T_NUMBER; }
|
|
|
|
[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; }
|
|
|
|
[0-9]+(\.[0-9]+)? { yylval->num = strtod(yytext, NULL); return T_NUMBER; }
|
2014-11-04 15:19:33 +01:00
|
|
|
= { yylval->csop = OpSetLiteral; return T_SET; }
|
|
|
|
\+= { yylval->csop = OpSetAdd; return T_SET_ADD; }
|
|
|
|
-= { yylval->csop = OpSetSubtract; return T_SET_SUBTRACT; }
|
|
|
|
\*= { yylval->csop = OpSetMultiply; return T_SET_MULTIPLY; }
|
|
|
|
\/= { yylval->csop = OpSetDivide; return T_SET_DIVIDE; }
|
2014-11-25 17:04:20 +01:00
|
|
|
\%= { yylval->csop = OpSetModulo; return T_SET_MODULO; }
|
|
|
|
\^= { yylval->csop = OpSetXor; return T_SET_XOR; }
|
|
|
|
\&= { yylval->csop = OpSetBinaryAnd; return T_SET_BINARY_AND; }
|
|
|
|
\|= { yylval->csop = OpSetBinaryOr; return T_SET_BINARY_OR; }
|
2014-11-09 19:48:28 +01:00
|
|
|
\+ return T_PLUS;
|
|
|
|
\- return T_MINUS;
|
|
|
|
\* return T_MULTIPLY;
|
|
|
|
\/ return T_DIVIDE_OP;
|
2014-11-25 17:04:20 +01:00
|
|
|
\% return T_MODULO;
|
|
|
|
\^ return T_XOR;
|
2014-11-09 19:48:28 +01:00
|
|
|
\& return T_BINARY_AND;
|
|
|
|
\| return T_BINARY_OR;
|
|
|
|
\< return T_LESS_THAN;
|
|
|
|
\> return T_GREATER_THAN;
|
2012-05-31 08:45:02 +02:00
|
|
|
}
|
|
|
|
|
2015-09-23 16:37:21 +02:00
|
|
|
\( { yyextra->m_IgnoreNewlines.push(true); return '('; }
|
|
|
|
\) { yyextra->m_IgnoreNewlines.pop(); return ')'; }
|
|
|
|
[\r\n]+ { yycolumn -= strlen(yytext) - 1; if (!yyextra->m_IgnoreNewlines.top()) { return T_NEWLINE; } }
|
2014-11-23 12:06:47 +01:00
|
|
|
<<EOF>> { if (!yyextra->m_Eof) { yyextra->m_Eof = true; return T_NEWLINE; } else { yyterminate(); } }
|
2012-06-05 15:05:15 +02:00
|
|
|
. return yytext[0];
|
2012-05-31 08:45:02 +02:00
|
|
|
|
2013-02-16 19:12:56 +01:00
|
|
|
%%
|
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
|
|
|
}
|