2012-06-06 14:38:28 +02:00
|
|
|
%code requires {
|
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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "i2-dyn.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2012-06-06 14:38:28 +02:00
|
|
|
#define YYLTYPE DebugInfo
|
|
|
|
|
|
|
|
}
|
2012-05-31 16:04:51 +02:00
|
|
|
|
2012-05-31 08:45:02 +02:00
|
|
|
%pure-parser
|
|
|
|
|
|
|
|
%locations
|
|
|
|
%defines
|
|
|
|
%error-verbose
|
|
|
|
|
2012-06-06 14:38:28 +02:00
|
|
|
%parse-param { ConfigCompiler *context }
|
2012-05-31 08:45:02 +02:00
|
|
|
%lex-param { void *scanner }
|
|
|
|
|
|
|
|
%union {
|
|
|
|
char *text;
|
|
|
|
int num;
|
2012-05-31 16:04:51 +02:00
|
|
|
icinga::Variant *variant;
|
2012-06-01 16:49:33 +02:00
|
|
|
icinga::ExpressionOperator op;
|
2012-05-31 08:45:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
%token <text> T_STRING
|
|
|
|
%token <num> T_NUMBER
|
2012-06-01 16:49:33 +02:00
|
|
|
%token T_NULL
|
2012-05-31 16:04:51 +02:00
|
|
|
%token <text> T_IDENTIFIER
|
|
|
|
%token <op> T_EQUAL
|
|
|
|
%token <op> T_PLUS_EQUAL
|
|
|
|
%token <op> T_MINUS_EQUAL
|
|
|
|
%token <op> T_MULTIPLY_EQUAL
|
|
|
|
%token <op> T_DIVIDE_EQUAL
|
2012-05-31 08:45:02 +02:00
|
|
|
%token T_ABSTRACT
|
|
|
|
%token T_LOCAL
|
|
|
|
%token T_OBJECT
|
|
|
|
%token T_INCLUDE
|
|
|
|
%token T_INHERITS
|
2012-06-01 16:49:33 +02:00
|
|
|
%type <variant> simplevalue
|
2012-05-31 16:04:51 +02:00
|
|
|
%type <variant> value
|
2012-06-05 15:05:15 +02:00
|
|
|
%type <variant> tuple
|
2012-06-01 16:49:33 +02:00
|
|
|
%type <variant> expressionlist
|
2012-05-31 16:04:51 +02:00
|
|
|
%type <op> operator
|
|
|
|
%left '+' '-'
|
|
|
|
%left '*' '/'
|
2012-05-31 08:45:02 +02:00
|
|
|
%{
|
|
|
|
|
2012-05-31 08:59:40 +02:00
|
|
|
int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
|
2012-05-31 08:45:02 +02:00
|
|
|
|
2012-06-06 14:38:28 +02:00
|
|
|
void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err)
|
2012-05-31 08:45:02 +02:00
|
|
|
{
|
2012-05-31 09:43:46 +02:00
|
|
|
stringstream message;
|
|
|
|
|
|
|
|
message << locp->first_line << ":" << locp->first_column
|
2012-05-31 08:45:02 +02:00
|
|
|
<< "-"
|
|
|
|
<< locp->last_line << ":" << locp->last_column
|
2012-05-31 09:43:46 +02:00
|
|
|
<< ": " << err << endl;
|
|
|
|
|
|
|
|
throw runtime_error(message.str());
|
2012-05-31 08:45:02 +02:00
|
|
|
}
|
|
|
|
|
2012-06-06 14:38:28 +02:00
|
|
|
int yyparse(ConfigCompiler *context);
|
|
|
|
|
|
|
|
static stack<ExpressionList::Ptr> m_ExpressionLists;
|
2012-07-06 14:33:10 +02:00
|
|
|
static ConfigItemBuilder::Ptr m_Item;
|
2012-06-06 14:38:28 +02:00
|
|
|
static bool m_Abstract;
|
|
|
|
static bool m_Local;
|
|
|
|
static Dictionary::Ptr m_Array;
|
2012-05-31 10:16:32 +02:00
|
|
|
|
2012-06-06 14:38:28 +02:00
|
|
|
void ConfigCompiler::Compile(void)
|
2012-05-31 10:16:32 +02:00
|
|
|
{
|
|
|
|
yyparse(this);
|
|
|
|
}
|
|
|
|
|
2012-05-31 09:43:46 +02:00
|
|
|
#define scanner (context->GetScanner())
|
2012-05-31 08:45:02 +02:00
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%%
|
|
|
|
statements: /* empty */
|
|
|
|
| statements statement
|
|
|
|
;
|
|
|
|
|
|
|
|
statement: object | include
|
|
|
|
;
|
|
|
|
|
|
|
|
include: T_INCLUDE T_STRING
|
2012-07-02 10:29:32 +02:00
|
|
|
{
|
|
|
|
context->HandleInclude($2);
|
|
|
|
}
|
2012-05-31 08:45:02 +02:00
|
|
|
|
2012-06-01 16:49:33 +02:00
|
|
|
object:
|
|
|
|
{
|
|
|
|
m_Abstract = false;
|
|
|
|
m_Local = false;
|
|
|
|
}
|
|
|
|
attributes T_OBJECT T_IDENTIFIER T_STRING
|
|
|
|
{
|
2012-07-06 14:33:10 +02:00
|
|
|
m_Item = boost::make_shared<ConfigItemBuilder>(yylloc);
|
|
|
|
m_Item->SetType($4);
|
|
|
|
m_Item->SetName($5);
|
2012-06-01 16:49:33 +02:00
|
|
|
}
|
|
|
|
inherits_specifier expressionlist
|
|
|
|
{
|
|
|
|
Object::Ptr exprl_object = *$8;
|
|
|
|
delete $8;
|
|
|
|
ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object);
|
2012-05-31 08:45:02 +02:00
|
|
|
|
2012-07-06 14:33:10 +02:00
|
|
|
m_Item->AddExpressionList(exprl);
|
|
|
|
m_Item->SetLocal(m_Local);
|
|
|
|
m_Item->SetAbstract(m_Abstract);
|
2012-06-01 16:49:33 +02:00
|
|
|
|
2012-07-06 14:33:10 +02:00
|
|
|
context->AddObject(m_Item->Compile());
|
|
|
|
m_Item.reset();
|
2012-06-01 16:49:33 +02:00
|
|
|
}
|
2012-05-31 08:45:02 +02:00
|
|
|
;
|
|
|
|
|
2012-06-01 16:49:33 +02:00
|
|
|
attributes: /* empty */
|
|
|
|
| attributes attribute
|
2012-05-31 08:45:02 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
attribute: T_ABSTRACT
|
2012-06-01 16:49:33 +02:00
|
|
|
{
|
|
|
|
m_Abstract = true;
|
|
|
|
}
|
2012-05-31 08:45:02 +02:00
|
|
|
| T_LOCAL
|
2012-06-01 16:49:33 +02:00
|
|
|
{
|
|
|
|
m_Local = true;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
inherits_list: inherits_item
|
2012-06-05 15:59:28 +02:00
|
|
|
| inherits_list ',' inherits_item
|
2012-05-31 08:45:02 +02:00
|
|
|
;
|
|
|
|
|
2012-06-01 16:49:33 +02:00
|
|
|
inherits_item: T_STRING
|
|
|
|
{
|
2012-07-06 14:33:10 +02:00
|
|
|
m_Item->AddParent($1);
|
2012-06-06 14:38:28 +02:00
|
|
|
free($1);
|
2012-06-01 16:49:33 +02:00
|
|
|
}
|
2012-05-31 08:45:02 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
inherits_specifier: /* empty */
|
|
|
|
| T_INHERITS inherits_list
|
|
|
|
;
|
|
|
|
|
2012-06-05 15:59:28 +02:00
|
|
|
expressionlist: '{'
|
2012-05-31 16:04:51 +02:00
|
|
|
{
|
2012-06-15 19:32:41 +02:00
|
|
|
m_ExpressionLists.push(boost::make_shared<ExpressionList>());
|
2012-05-31 16:04:51 +02:00
|
|
|
}
|
2012-06-01 16:49:33 +02:00
|
|
|
expressions
|
2012-06-05 15:59:28 +02:00
|
|
|
'}'
|
2012-05-31 16:04:51 +02:00
|
|
|
{
|
2012-06-01 16:49:33 +02:00
|
|
|
$$ = new Variant(m_ExpressionLists.top());
|
|
|
|
m_ExpressionLists.pop();
|
2012-05-31 16:04:51 +02:00
|
|
|
}
|
2012-05-31 08:45:02 +02:00
|
|
|
;
|
|
|
|
|
2012-06-29 10:39:36 +02:00
|
|
|
expressions: expressions_inner
|
|
|
|
| expressions_inner ','
|
|
|
|
|
|
|
|
expressions_inner: /* empty */
|
2012-06-01 16:49:33 +02:00
|
|
|
| expression
|
2012-06-29 10:39:36 +02:00
|
|
|
| expressions_inner ',' expression
|
2012-05-31 08:45:02 +02:00
|
|
|
;
|
|
|
|
|
2012-06-01 16:49:33 +02:00
|
|
|
expression: T_IDENTIFIER operator value
|
2012-05-31 16:04:51 +02:00
|
|
|
{
|
2012-06-06 14:38:28 +02:00
|
|
|
Expression expr($1, $2, *$3, yylloc);
|
2012-05-31 16:04:51 +02:00
|
|
|
free($1);
|
|
|
|
delete $3;
|
2012-06-01 16:49:33 +02:00
|
|
|
|
|
|
|
m_ExpressionLists.top()->AddExpression(expr);
|
|
|
|
}
|
2012-06-05 15:59:28 +02:00
|
|
|
| T_IDENTIFIER '[' T_STRING ']' operator value
|
2012-06-01 16:49:33 +02:00
|
|
|
{
|
2012-06-06 14:38:28 +02:00
|
|
|
Expression subexpr($3, $5, *$6, yylloc);
|
2012-06-01 16:49:33 +02:00
|
|
|
free($3);
|
|
|
|
delete $6;
|
|
|
|
|
2012-06-15 19:32:41 +02:00
|
|
|
ExpressionList::Ptr subexprl = boost::make_shared<ExpressionList>();
|
2012-06-01 16:49:33 +02:00
|
|
|
subexprl->AddExpression(subexpr);
|
|
|
|
|
2012-06-06 14:38:28 +02:00
|
|
|
Expression expr($1, OperatorPlus, subexprl, yylloc);
|
|
|
|
free($1);
|
2012-06-01 16:49:33 +02:00
|
|
|
|
|
|
|
m_ExpressionLists.top()->AddExpression(expr);
|
|
|
|
}
|
|
|
|
| T_STRING
|
|
|
|
{
|
2012-06-06 14:38:28 +02:00
|
|
|
Expression expr($1, OperatorSet, $1, yylloc);
|
2012-06-01 16:49:33 +02:00
|
|
|
free($1);
|
2012-06-06 14:38:28 +02:00
|
|
|
|
2012-06-01 16:49:33 +02:00
|
|
|
m_ExpressionLists.top()->AddExpression(expr);
|
2012-05-31 16:04:51 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
operator: T_EQUAL
|
|
|
|
| T_PLUS_EQUAL
|
|
|
|
| T_MINUS_EQUAL
|
|
|
|
| T_MULTIPLY_EQUAL
|
|
|
|
| T_DIVIDE_EQUAL
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2012-05-31 08:45:02 +02:00
|
|
|
;
|
|
|
|
|
2012-06-01 16:49:33 +02:00
|
|
|
simplevalue: T_STRING
|
2012-05-31 16:04:51 +02:00
|
|
|
{
|
|
|
|
$$ = new Variant($1);
|
2012-06-06 14:38:28 +02:00
|
|
|
free($1);
|
2012-05-31 16:04:51 +02:00
|
|
|
}
|
|
|
|
| T_NUMBER
|
|
|
|
{
|
|
|
|
$$ = new Variant($1);
|
|
|
|
}
|
2012-06-01 16:49:33 +02:00
|
|
|
| T_NULL
|
|
|
|
{
|
|
|
|
$$ = new Variant();
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
value: simplevalue
|
2012-06-05 15:05:15 +02:00
|
|
|
| tuple
|
2012-06-01 16:49:33 +02:00
|
|
|
| expressionlist
|
2012-05-31 16:04:51 +02:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2012-05-31 08:45:02 +02:00
|
|
|
;
|
|
|
|
|
2012-06-05 15:59:28 +02:00
|
|
|
tuple: '('
|
2012-05-31 16:04:51 +02:00
|
|
|
{
|
2012-06-15 19:32:41 +02:00
|
|
|
m_Array = boost::make_shared<Dictionary>();
|
2012-05-31 16:04:51 +02:00
|
|
|
}
|
2012-06-05 15:05:15 +02:00
|
|
|
tupleitems
|
2012-06-05 15:59:28 +02:00
|
|
|
')'
|
2012-05-31 16:04:51 +02:00
|
|
|
{
|
2012-06-01 16:49:33 +02:00
|
|
|
$$ = new Variant(m_Array);
|
|
|
|
m_Array.reset();
|
2012-05-31 16:04:51 +02:00
|
|
|
}
|
2012-05-31 08:45:02 +02:00
|
|
|
;
|
|
|
|
|
2012-06-05 15:05:15 +02:00
|
|
|
tupleitem: simplevalue
|
2012-05-31 16:04:51 +02:00
|
|
|
{
|
2012-06-01 16:49:33 +02:00
|
|
|
m_Array->AddUnnamedProperty(*$1);
|
2012-05-31 16:04:51 +02:00
|
|
|
delete $1;
|
|
|
|
}
|
2012-06-05 15:05:15 +02:00
|
|
|
|
2012-06-29 10:39:36 +02:00
|
|
|
tupleitems: tupleitems_inner
|
|
|
|
| tupleitems_inner ','
|
|
|
|
|
|
|
|
tupleitems_inner:
|
2012-06-05 15:05:15 +02:00
|
|
|
/* empty */
|
|
|
|
| tupleitem
|
2012-06-29 10:39:36 +02:00
|
|
|
| tupleitems_inner ',' tupleitem
|
2012-05-31 08:45:02 +02:00
|
|
|
;
|
|
|
|
%%
|