2013-11-03 12:40:39 +01:00
%{
2014-11-23 12:06:47 +01:00
#define YYDEBUG 1
2014-03-21 10:22:59 +01: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/i2-config.hpp"
#include "config/configcompiler.hpp"
2014-10-16 17:44:06 +02:00
#include "config/expression.hpp"
2014-05-25 16:23:35 +02:00
#include "config/applyrule.hpp"
#include "config/objectrule.hpp"
#include "base/value.hpp"
#include "base/utility.hpp"
#include "base/exception.hpp"
2015-08-15 20:28:05 +02:00
#include "base/configtype.hpp"
2014-12-18 15:11:57 +01:00
#include "base/exception.hpp"
2013-03-16 21:18:53 +01:00
#include <sstream>
#include <stack>
2013-03-27 13:50:53 +01:00
#include <boost/foreach.hpp>
2012-05-31 16:04:51 +02:00
2014-12-14 11:33:45 +01:00
#define YYLTYPE icinga::CompilerDebugInfo
2014-03-21 10:22:59 +01:00
#define YYERROR_VERBOSE
2014-03-21 14:43:45 +01:00
#define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
2014-03-21 15:41:00 +01:00
if (N) { \
2014-03-21 14:43:45 +01:00
(Current).Path = YYRHSLOC(Rhs, 1).Path; \
(Current).FirstLine = YYRHSLOC(Rhs, 1).FirstLine; \
(Current).FirstColumn = YYRHSLOC(Rhs, 1).FirstColumn; \
(Current).LastLine = YYRHSLOC(Rhs, N).LastLine; \
(Current).LastColumn = YYRHSLOC(Rhs, N).LastColumn; \
} else { \
(Current).Path = YYRHSLOC(Rhs, 0).Path; \
(Current).FirstLine = (Current).LastLine = \
YYRHSLOC(Rhs, 0).LastLine; \
(Current).FirstColumn = (Current).LastColumn = \
YYRHSLOC(Rhs, 0).LastColumn; \
} \
} while (0)
2014-03-21 10:22:59 +01:00
#define YY_LOCATION_PRINT(file, loc) \
do { \
2014-10-13 09:46:58 +02:00
std::ostringstream msgbuf; \
msgbuf << loc; \
std::string str = msgbuf.str(); \
fputs(str.c_str(), file); \
2014-03-21 10:22:59 +01:00
} while (0)
2012-06-06 14:38:28 +02:00
2013-11-03 12:40:39 +01:00
using namespace icinga;
2014-11-09 19:48:28 +01:00
template<typename T>
2014-12-14 11:33:45 +01:00
static void MakeRBinaryOp(Expression** result, Expression *left, Expression *right, const DebugInfo& diLeft, const DebugInfo& diRight)
2014-03-30 05:04:58 +02:00
{
2014-11-09 19:48:28 +01:00
*result = new T(left, right, DebugInfoRange(diLeft, diRight));
2014-03-30 05:04:58 +02:00
}
2013-11-03 12:40:39 +01:00
%}
2012-05-31 16:04:51 +02:00
2012-05-31 08:45:02 +02:00
%pure-parser
%locations
%defines
%error-verbose
2014-12-14 11:33:45 +01:00
%glr-parser
2012-05-31 08:45:02 +02:00
2015-01-08 10:30:34 +01:00
%parse-param { std::vector<std::pair<Expression *, EItemInfo> > *llist }
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 {
2015-09-29 07:09:35 +02:00
String *text;
2012-07-11 21:03:22 +02:00
double num;
2014-12-10 09:04:49 +01:00
bool boolean;
2014-11-09 19:48:28 +01:00
icinga::Expression *expr;
2015-03-07 14:47:54 +01:00
icinga::DictExpression *dexpr;
2014-11-04 15:19:33 +01:00
CombinedSetOp csop;
2013-03-27 13:50:53 +01:00
std::vector<String> *slist;
2015-01-08 10:30:34 +01:00
std::vector<std::pair<Expression *, EItemInfo> > *llist;
2014-11-09 19:48:28 +01:00
std::vector<Expression *> *elist;
2015-02-26 13:50:25 +01:00
std::vector<std::pair<Expression *, Expression *> > *ebranchlist;
std::pair<Expression *, Expression *> *ebranch;
2014-11-22 12:21:28 +01:00
std::pair<String, Expression *> *cvitem;
std::map<String, Expression *> *cvlist;
2014-12-13 17:48:58 +01:00
icinga::ScopeSpecifier scope;
2012-05-31 08:45:02 +02:00
}
2014-03-31 18:38:15 +02:00
%token T_NEWLINE "new-line"
2012-05-31 08:45:02 +02:00
%token <text> T_STRING
2013-02-01 22:44:58 +01:00
%token <text> T_STRING_ANGLE
2012-05-31 08:45:02 +02:00
%token <num> T_NUMBER
2014-12-10 09:04:49 +01:00
%token <boolean> T_BOOLEAN
2012-06-01 16:49:33 +02:00
%token T_NULL
2012-05-31 16:04:51 +02:00
%token <text> T_IDENTIFIER
2014-03-23 11:27:40 +01:00
2014-11-04 15:19:33 +01:00
%token <csop> T_SET "= (T_SET)"
%token <csop> T_SET_ADD "+= (T_SET_ADD)"
%token <csop> T_SET_SUBTRACT "-= (T_SET_SUBTRACT)"
%token <csop> T_SET_MULTIPLY "*= (T_SET_MULTIPLY)"
%token <csop> T_SET_DIVIDE "/= (T_SET_DIVIDE)"
2014-11-25 17:04:20 +01:00
%token <csop> T_SET_MODULO "%= (T_SET_MODULO)"
%token <csop> T_SET_XOR "^= (T_SET_XOR)"
%token <csop> T_SET_BINARY_AND "&= (T_SET_BINARY_AND)"
%token <csop> T_SET_BINARY_OR "|= (T_SET_BINARY_OR)"
2014-03-23 11:27:40 +01:00
2014-11-09 19:48:28 +01:00
%token T_SHIFT_LEFT "<< (T_SHIFT_LEFT)"
%token T_SHIFT_RIGHT ">> (T_SHIFT_RIGHT)"
%token T_EQUAL "== (T_EQUAL)"
%token T_NOT_EQUAL "!= (T_NOT_EQUAL)"
%token T_IN "in (T_IN)"
%token T_NOT_IN "!in (T_NOT_IN)"
%token T_LOGICAL_AND "&& (T_LOGICAL_AND)"
%token T_LOGICAL_OR "|| (T_LOGICAL_OR)"
%token T_LESS_THAN_OR_EQUAL "<= (T_LESS_THAN_OR_EQUAL)"
%token T_GREATER_THAN_OR_EQUAL ">= (T_GREATER_THAN_OR_EQUAL)"
%token T_PLUS "+ (T_PLUS)"
%token T_MINUS "- (T_MINUS)"
%token T_MULTIPLY "* (T_MULTIPLY)"
%token T_DIVIDE_OP "/ (T_DIVIDE_OP)"
2014-11-25 17:04:20 +01:00
%token T_MODULO "% (T_MODULO)"
%token T_XOR "^ (T_XOR)"
2014-11-09 19:48:28 +01:00
%token T_BINARY_AND "& (T_BINARY_AND)"
%token T_BINARY_OR "| (T_BINARY_OR)"
%token T_LESS_THAN "< (T_LESS_THAN)"
%token T_GREATER_THAN "> (T_GREATER_THAN)"
2014-03-23 11:27:40 +01:00
2014-12-15 16:09:17 +01:00
%token T_VAR "var (T_VAR)"
2015-01-16 13:04:34 +01:00
%token T_GLOBALS "globals (T_GLOBALS)"
%token T_LOCALS "locals (T_LOCALS)"
2014-12-15 16:09:17 +01:00
%token T_CONST "const (T_CONST)"
2014-11-22 12:21:28 +01:00
%token T_USE "use (T_USE)"
2013-03-27 13:50:53 +01:00
%token T_OBJECT "object (T_OBJECT)"
%token T_TEMPLATE "template (T_TEMPLATE)"
%token T_INCLUDE "include (T_INCLUDE)"
2013-11-29 10:39:48 +01:00
%token T_INCLUDE_RECURSIVE "include_recursive (T_INCLUDE_RECURSIVE)"
2015-07-21 09:32:17 +02:00
%token T_INCLUDE_ZONES "include_zones (T_INCLUDE_ZONES)"
2013-03-27 13:50:53 +01:00
%token T_LIBRARY "library (T_LIBRARY)"
%token T_INHERITS "inherits (T_INHERITS)"
2014-03-18 11:44:09 +01:00
%token T_APPLY "apply (T_APPLY)"
2014-04-05 12:56:56 +02:00
%token T_TO "to (T_TO)"
2014-03-18 11:44:09 +01:00
%token T_WHERE "where (T_WHERE)"
2014-03-27 12:30:24 +01:00
%token T_IMPORT "import (T_IMPORT)"
2014-03-28 13:25:40 +01:00
%token T_ASSIGN "assign (T_ASSIGN)"
%token T_IGNORE "ignore (T_IGNORE)"
2014-03-30 15:04:53 +02:00
%token T_FUNCTION "function (T_FUNCTION)"
2014-04-09 10:36:57 +02:00
%token T_RETURN "return (T_RETURN)"
2015-02-19 12:57:52 +01:00
%token T_BREAK "break (T_BREAK)"
%token T_CONTINUE "continue (T_CONTINUE)"
2014-05-10 11:26:56 +02:00
%token T_FOR "for (T_FOR)"
2014-11-24 09:53:45 +01:00
%token T_IF "if (T_IF)"
%token T_ELSE "else (T_ELSE)"
2015-01-23 15:54:27 +01:00
%token T_WHILE "while (T_WHILE)"
2015-08-24 11:04:26 +02:00
%token T_THROW "throw (T_THROW)"
2014-11-04 11:01:00 +01:00
%token T_FOLLOWS "=> (T_FOLLOWS)"
2015-01-30 09:49:57 +01:00
%token T_NULLARY_LAMBDA_BEGIN "{{ (T_NULLARY_LAMBDA_BEGIN)"
%token T_NULLARY_LAMBDA_END "}} (T_NULLARY_LAMBDA_END)"
2014-03-28 16:32:15 +01:00
2013-01-29 12:11:05 +01:00
%type <text> identifier
2014-11-09 19:48:28 +01:00
%type <elist> rterm_items
%type <elist> rterm_items_inner
%type <slist> identifier_items
%type <slist> identifier_items_inner
2014-11-04 15:19:33 +01:00
%type <csop> combined_set_op
2015-01-08 10:30:34 +01:00
%type <llist> statements
%type <llist> lterm_items
%type <llist> lterm_items_inner
2014-11-09 19:48:28 +01:00
%type <expr> rterm
%type <expr> rterm_array
2015-03-07 14:47:54 +01:00
%type <dexpr> rterm_scope_require_side_effect
%type <dexpr> rterm_scope
2015-02-26 13:50:25 +01:00
%type <ebranchlist> else_if_branches
%type <ebranch> else_if_branch
2015-01-08 09:33:24 +01:00
%type <expr> rterm_side_effect
%type <expr> rterm_no_side_effect
2014-11-09 19:48:28 +01:00
%type <expr> lterm
%type <expr> object
%type <expr> apply
%type <expr> optional_rterm
2014-04-05 12:56:56 +02:00
%type <text> target_type_specifier
2014-11-22 12:21:28 +01:00
%type <cvlist> use_specifier
%type <cvlist> use_specifier_items
%type <cvitem> use_specifier_item
2014-11-25 08:59:55 +01:00
%type <num> object_declaration
2014-03-28 16:32:15 +01:00
2014-12-13 14:06:19 +01:00
%right T_FOLLOWS
2015-07-21 09:32:17 +02:00
%right T_INCLUDE T_INCLUDE_RECURSIVE T_INCLUDE_ZONES T_OBJECT T_TEMPLATE T_APPLY T_IMPORT T_ASSIGN T_IGNORE T_WHERE
2014-12-14 11:33:45 +01:00
%right T_FUNCTION T_FOR
2015-02-02 12:35:07 +01:00
%left T_SET T_SET_ADD T_SET_SUBTRACT T_SET_MULTIPLY T_SET_DIVIDE T_SET_MODULO T_SET_XOR T_SET_BINARY_AND T_SET_BINARY_OR
2014-03-18 15:29:04 +01:00
%left T_LOGICAL_OR
%left T_LOGICAL_AND
2015-02-19 12:57:52 +01:00
%left T_RETURN T_BREAK T_CONTINUE
2014-11-22 23:02:12 +01:00
%left T_IDENTIFIER
2014-03-30 05:04:58 +02:00
%left T_BINARY_OR
2015-02-02 12:35:07 +01:00
%left T_XOR
2014-03-30 05:04:58 +02:00
%left T_BINARY_AND
2015-02-02 12:35:07 +01:00
%nonassoc T_EQUAL T_NOT_EQUAL
2014-11-22 23:02:12 +01:00
%left T_IN T_NOT_IN
2015-02-02 12:35:07 +01:00
%nonassoc T_LESS_THAN T_LESS_THAN_OR_EQUAL T_GREATER_THAN T_GREATER_THAN_OR_EQUAL
2014-03-30 05:04:58 +02:00
%left T_SHIFT_LEFT T_SHIFT_RIGHT
2014-03-28 12:17:22 +01:00
%left T_PLUS T_MINUS
2015-02-02 12:35:07 +01:00
%left T_MULTIPLY T_DIVIDE_OP T_MODULO
2014-12-16 06:18:39 +01:00
%left UNARY_MINUS UNARY_PLUS
2014-03-30 05:04:58 +02:00
%right '!' '~'
%left '.' '(' '['
2015-01-16 13:04:34 +01:00
%left T_VAR T_THIS T_GLOBALS T_LOCALS
2014-11-22 23:02:12 +01:00
%right ';' ','
2014-12-13 14:06:19 +01:00
%right T_NEWLINE
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
2014-12-14 11:33:45 +01:00
extern int yydebug;
2015-02-10 13:27:02 +01:00
void yyerror(const YYLTYPE *locp, std::vector<std::pair<Expression *, EItemInfo> > *, ConfigCompiler *context, const char *err)
2012-05-31 08:45:02 +02:00
{
2015-02-10 15:53:20 +01:00
bool incomplete = context && context->m_Eof && (context->m_OpenBraces > 0);
2015-02-10 13:27:02 +01:00
BOOST_THROW_EXCEPTION(ScriptError(err, *locp, incomplete));
2012-05-31 08:45:02 +02:00
}
2015-01-08 10:30:34 +01:00
int yyparse(std::vector<std::pair<Expression *, EItemInfo> > *llist, ConfigCompiler *context);
2012-06-06 14:38:28 +02:00
2014-11-15 08:20:22 +01:00
Expression *ConfigCompiler::Compile(void)
2012-05-31 10:16:32 +02:00
{
2015-01-08 10:30:34 +01:00
std::vector<std::pair<Expression *, EItemInfo> > llist;
2014-11-15 08:20:22 +01:00
2014-12-14 11:33:45 +01:00
//yydebug = 1;
2015-09-23 16:37:21 +02:00
m_IgnoreNewlines.push(false);
2015-01-08 10:30:34 +01:00
if (yyparse(&llist, this) != 0)
2014-11-27 08:04:07 +01:00
return NULL;
2014-11-15 08:20:22 +01:00
2015-09-23 16:37:21 +02:00
m_IgnoreNewlines.pop();
2015-01-08 10:30:34 +01:00
std::vector<Expression *> dlist;
typedef std::pair<Expression *, EItemInfo> EListItem;
int num = 0;
BOOST_FOREACH(const EListItem& litem, llist) {
if (!litem.second.SideEffect && num != llist.size() - 1) {
yyerror(&litem.second.DebugInfo, NULL, NULL, "Value computed is not used.");
}
dlist.push_back(litem.first);
num++;
}
DictExpression *expr = new DictExpression(dlist);
2014-11-27 08:04:07 +01:00
expr->MakeInline();
return expr;
2012-05-31 10:16:32 +02:00
}
2012-05-31 09:43:46 +02:00
#define scanner (context->GetScanner())
2012-05-31 08:45:02 +02:00
%}
%%
2014-11-25 08:42:27 +01:00
script: statements
{
2015-01-08 10:30:34 +01:00
llist->swap(*$1);
2014-11-25 08:42:27 +01:00
delete $1;
}
;
2014-12-14 11:33:45 +01:00
statements: newlines lterm_items
2014-11-25 08:59:55 +01:00
{
$$ = $2;
}
| lterm_items
2012-05-31 08:45:02 +02:00
;
2014-11-25 08:59:55 +01:00
lterm_items: /* empty */
{
2015-01-08 10:30:34 +01:00
$$ = new std::vector<std::pair<Expression *, EItemInfo> >();
2014-11-25 08:59:55 +01:00
}
| lterm_items_inner
2015-01-08 10:30:34 +01:00
| lterm_items_inner sep
;
lterm_items_inner: lterm %dprec 2
2014-03-22 09:50:44 +01:00
{
2015-01-08 10:30:34 +01:00
$$ = new std::vector<std::pair<Expression *, EItemInfo> >();
EItemInfo info = { true, @1 };
$$->push_back(std::make_pair($1, info));
2014-12-14 11:33:45 +01:00
}
2015-01-08 10:30:34 +01:00
| rterm_no_side_effect
2014-12-14 11:33:45 +01:00
{
2015-01-08 10:30:34 +01:00
$$ = new std::vector<std::pair<Expression *, EItemInfo> >();
EItemInfo info = { false, @1 };
$$->push_back(std::make_pair($1, info));
2014-12-14 11:33:45 +01:00
}
2015-01-08 10:30:34 +01:00
| lterm_items_inner sep lterm %dprec 1
2014-11-25 08:42:27 +01:00
{
2015-01-08 10:30:34 +01:00
if ($1)
$$ = $1;
else
$$ = new std::vector<std::pair<Expression *, EItemInfo> >();
2012-05-31 08:45:02 +02:00
2015-01-08 10:30:34 +01:00
if ($3) {
EItemInfo info = { true, @3 };
$$->push_back(std::make_pair($3, info));
}
2014-11-25 08:59:55 +01:00
}
2015-01-08 10:30:34 +01:00
| lterm_items_inner sep rterm_no_side_effect %dprec 1
2014-11-25 08:59:55 +01:00
{
if ($1)
$$ = $1;
else
2015-01-08 10:30:34 +01:00
$$ = new std::vector<std::pair<Expression *, EItemInfo> >();
2014-11-25 08:59:55 +01:00
2015-01-08 10:30:34 +01:00
if ($3) {
EItemInfo info = { false, @3 };
$$->push_back(std::make_pair($3, info));
}
2014-11-25 08:59:55 +01:00
}
;
2013-01-29 12:11:05 +01:00
identifier: T_IDENTIFIER
| T_STRING
;
2013-02-11 09:55:32 +01:00
object:
2012-06-01 16:49:33 +02:00
{
2014-11-25 09:40:32 +01:00
context->m_ObjectAssign.push(true);
context->m_SeenAssign.push(false);
2015-07-02 17:51:52 +02:00
context->m_SeenIgnore.push(false);
2014-11-25 09:40:32 +01:00
context->m_Assign.push(NULL);
context->m_Ignore.push(NULL);
2012-06-01 16:49:33 +02:00
}
2015-02-09 08:12:42 +01:00
object_declaration identifier optional_rterm use_specifier rterm_scope_require_side_effect
2012-06-01 16:49:33 +02:00
{
2014-11-25 09:40:32 +01:00
context->m_ObjectAssign.pop();
2014-04-23 12:44:36 +02:00
2014-11-25 08:59:55 +01:00
bool abstract = $2;
2013-05-08 10:50:56 +02:00
2015-09-29 07:09:35 +02:00
String type = *$3;
delete $3;
2013-05-07 09:22:39 +02:00
2015-03-07 14:47:54 +01:00
$6->MakeInline();
2012-06-01 16:49:33 +02:00
2014-11-25 09:40:32 +01:00
bool seen_assign = context->m_SeenAssign.top();
context->m_SeenAssign.pop();
2014-11-01 06:25:58 +01:00
2015-07-02 17:51:52 +02:00
bool seen_ignore = context->m_SeenIgnore.top();
context->m_SeenIgnore.pop();
2014-11-25 09:40:32 +01:00
Expression *ignore = context->m_Ignore.top();
context->m_Ignore.pop();
2014-11-01 06:25:58 +01:00
2014-11-25 09:40:32 +01:00
Expression *assign = context->m_Assign.top();
context->m_Assign.pop();
2014-04-23 12:44:36 +02:00
2014-11-10 12:05:45 +01:00
Expression *filter = NULL;
if (seen_assign) {
if (!ObjectRule::IsValidSourceType(type))
2014-11-30 23:32:13 +01:00
BOOST_THROW_EXCEPTION(ScriptError("object rule 'assign' cannot be used for type '" + type + "'", DebugInfoRange(@2, @4)));
2014-11-10 12:05:45 +01:00
if (ignore) {
Expression *rex = new LogicalNegateExpression(ignore, DebugInfoRange(@2, @5));
filter = new LogicalAndExpression(assign, rex, DebugInfoRange(@2, @5));
} else
filter = assign;
2015-07-02 17:51:52 +02:00
} else if (seen_ignore) {
if (!ObjectRule::IsValidSourceType(type))
BOOST_THROW_EXCEPTION(ScriptError("object rule 'ignore' cannot be used for type '" + type + "'", DebugInfoRange(@2, @4)));
2015-07-16 13:55:53 +02:00
else
BOOST_THROW_EXCEPTION(ScriptError("object rule 'ignore' is missing 'assign' for type '" + type + "'", DebugInfoRange(@2, @4)));
2014-11-10 12:05:45 +01:00
}
2015-08-28 17:58:29 +02:00
$$ = new ObjectExpression(abstract, type, $4, filter, context->GetZone(), context->GetPackage(), $5, $6, DebugInfoRange(@2, @5));
2012-06-01 16:49:33 +02:00
}
2012-05-31 08:45:02 +02:00
;
2013-09-25 14:10:26 +02:00
object_declaration: T_OBJECT
2014-11-25 08:59:55 +01:00
{
$$ = false;
}
2013-02-16 09:18:34 +01:00
| T_TEMPLATE
{
2014-11-25 08:59:55 +01:00
$$ = true;
2013-02-16 09:18:34 +01:00
}
2014-11-25 08:59:55 +01:00
;
2013-02-16 09:18:34 +01:00
2014-12-14 11:33:45 +01:00
identifier_items: /* empty */
{
$$ = new std::vector<String>();
}
| identifier_items_inner
2014-03-30 15:04:53 +02:00
| identifier_items_inner ','
;
2014-12-14 11:33:45 +01:00
identifier_items_inner: identifier
2014-03-30 15:04:53 +02:00
{
2014-11-09 19:48:28 +01:00
$$ = new std::vector<String>();
2015-09-29 07:09:35 +02:00
$$->push_back(*$1);
delete $1;
2014-03-30 15:04:53 +02:00
}
| identifier_items_inner ',' identifier
{
if ($1)
$$ = $1;
else
2014-11-09 19:48:28 +01:00
$$ = new std::vector<String>();
2014-03-30 15:04:53 +02:00
2015-09-29 07:09:35 +02:00
$$->push_back(*$3);
delete $3;
2014-03-30 15:04:53 +02:00
}
;
2014-12-14 11:33:45 +01:00
combined_set_op: T_SET
| T_SET_ADD
| T_SET_SUBTRACT
| T_SET_MULTIPLY
| T_SET_DIVIDE
| T_SET_MODULO
| T_SET_XOR
| T_SET_BINARY_AND
| T_SET_BINARY_OR
2014-11-04 15:19:33 +01:00
;
2015-08-27 14:47:31 +02:00
lterm: T_LIBRARY rterm
2013-03-27 13:50:53 +01:00
{
2015-08-27 14:47:31 +02:00
$$ = new LibraryExpression($2, @$);
2013-03-27 13:50:53 +01:00
}
2014-12-14 11:33:45 +01:00
| rterm combined_set_op rterm
2014-12-13 17:48:58 +01:00
{
2015-01-08 15:01:13 +01:00
$$ = new SetExpression($1, $2, $3, @$);
2014-12-13 17:48:58 +01:00
}
2014-11-24 07:18:37 +01:00
| T_INCLUDE T_STRING
2014-11-15 08:20:22 +01:00
{
2015-09-29 07:09:35 +02:00
$$ = context->HandleInclude(*$2, false, @$);
delete $2;
2014-11-15 08:20:22 +01:00
}
| T_INCLUDE T_STRING_ANGLE
{
2015-09-29 07:09:35 +02:00
$$ = context->HandleInclude(*$2, true, @$);
delete $2;
2014-11-15 08:20:22 +01:00
}
2014-11-24 07:18:37 +01:00
| T_INCLUDE_RECURSIVE T_STRING
2014-11-15 08:20:22 +01:00
{
2015-09-29 07:09:35 +02:00
$$ = context->HandleIncludeRecursive(*$2, "*.conf", @$);
delete $2;
2014-11-15 08:20:22 +01:00
}
2014-11-24 07:18:37 +01:00
| T_INCLUDE_RECURSIVE T_STRING ',' T_STRING
2014-11-15 08:20:22 +01:00
{
2015-09-29 07:09:35 +02:00
$$ = context->HandleIncludeRecursive(*$2, *$4, @$);
delete $2;
delete $4;
2014-11-15 08:20:22 +01:00
}
2015-07-21 09:32:17 +02:00
| T_INCLUDE_ZONES T_STRING ',' T_STRING
{
2015-09-29 07:09:35 +02:00
$$ = context->HandleIncludeZones(*$2, *$4, "*.conf", @$);
delete $2;
delete $4;
2015-07-21 09:32:17 +02:00
}
| T_INCLUDE_ZONES T_STRING ',' T_STRING ',' T_STRING
{
2015-09-29 07:09:35 +02:00
$$ = context->HandleIncludeZones(*$2, *$4, *$6, @$);
delete $2;
delete $4;
delete $6;
2015-07-21 09:32:17 +02:00
}
2014-03-28 13:25:40 +01:00
| T_IMPORT rterm
{
2015-01-08 15:01:13 +01:00
$$ = new ImportExpression($2, @$);
2014-03-28 13:25:40 +01:00
}
| T_ASSIGN T_WHERE rterm
{
2014-11-25 09:40:32 +01:00
if ((context->m_Apply.empty() || !context->m_Apply.top()) && (context->m_ObjectAssign.empty() || !context->m_ObjectAssign.top()))
2015-01-08 15:01:13 +01:00
BOOST_THROW_EXCEPTION(ScriptError("'assign' keyword not valid in this context.", @$));
2014-03-28 13:25:40 +01:00
2014-11-25 09:40:32 +01:00
context->m_SeenAssign.top() = true;
2014-04-07 13:04:13 +02:00
2014-11-25 09:40:32 +01:00
if (context->m_Assign.top())
2015-01-08 15:01:13 +01:00
context->m_Assign.top() = new LogicalOrExpression(context->m_Assign.top(), $3, @$);
2014-11-10 12:05:45 +01:00
else
2014-11-25 09:40:32 +01:00
context->m_Assign.top() = $3;
2014-03-28 13:25:40 +01:00
2014-11-09 19:48:28 +01:00
$$ = MakeLiteral();
2014-03-28 13:25:40 +01:00
}
| T_IGNORE T_WHERE rterm
{
2014-11-25 09:40:32 +01:00
if ((context->m_Apply.empty() || !context->m_Apply.top()) && (context->m_ObjectAssign.empty() || !context->m_ObjectAssign.top()))
2015-01-08 15:01:13 +01:00
BOOST_THROW_EXCEPTION(ScriptError("'ignore' keyword not valid in this context.", @$));
2014-03-28 13:25:40 +01:00
2015-07-02 17:51:52 +02:00
context->m_SeenIgnore.top() = true;
2014-11-25 09:40:32 +01:00
if (context->m_Ignore.top())
2015-01-08 15:01:13 +01:00
context->m_Ignore.top() = new LogicalOrExpression(context->m_Ignore.top(), $3, @$);
2014-11-10 12:05:45 +01:00
else
2014-11-25 09:40:32 +01:00
context->m_Ignore.top() = $3;
2014-03-28 13:25:40 +01:00
2014-11-09 19:48:28 +01:00
$$ = MakeLiteral();
2014-03-28 13:25:40 +01:00
}
2015-01-16 08:41:27 +01:00
| T_RETURN optional_rterm
2014-04-09 10:36:57 +02:00
{
2015-01-08 15:01:13 +01:00
$$ = new ReturnExpression($2, @$);
2014-04-09 10:36:57 +02:00
}
2015-02-19 12:57:52 +01:00
| T_BREAK
{
$$ = new BreakExpression(@$);
}
| T_CONTINUE
{
$$ = new ContinueExpression(@$);
}
2014-03-30 15:04:53 +02:00
| apply
| object
2015-01-08 10:30:34 +01:00
| T_FOR '(' identifier T_FOLLOWS identifier T_IN rterm ')' rterm_scope_require_side_effect
2014-12-11 13:12:35 +01:00
{
2015-03-07 14:47:54 +01:00
$9->MakeInline();
2014-12-11 13:12:35 +01:00
2015-09-29 07:09:35 +02:00
$$ = new ForExpression(*$3, *$5, $7, $9, @$);
delete $3;
delete $5;
2014-12-11 13:12:35 +01:00
}
2015-01-08 10:30:34 +01:00
| T_FOR '(' identifier T_IN rterm ')' rterm_scope_require_side_effect
2014-12-11 13:12:35 +01:00
{
2015-03-07 14:47:54 +01:00
$7->MakeInline();
2014-12-11 13:12:35 +01:00
2015-09-29 07:09:35 +02:00
$$ = new ForExpression(*$3, "", $5, $7, @$);
delete $3;
2014-12-11 13:12:35 +01:00
}
2014-12-13 17:48:58 +01:00
| T_FUNCTION identifier '(' identifier_items ')' use_specifier rterm_scope
{
2015-03-07 14:47:54 +01:00
$7->MakeInline();
2014-12-13 17:48:58 +01:00
2015-03-07 14:47:54 +01:00
FunctionExpression *fexpr = new FunctionExpression(*$4, $6, $7, @$);
2014-12-13 17:48:58 +01:00
delete $4;
2015-09-29 07:09:35 +02:00
$$ = new SetExpression(MakeIndexer(ScopeThis, *$2), OpSetLiteral, fexpr, @$);
delete $2;
2014-12-13 17:48:58 +01:00
}
2014-12-15 16:09:17 +01:00
| T_CONST T_IDENTIFIER T_SET rterm
2014-12-13 17:48:58 +01:00
{
2015-09-29 07:09:35 +02:00
$$ = new SetExpression(MakeIndexer(ScopeGlobal, *$2), OpSetLiteral, $4);
delete $2;
2014-12-13 17:48:58 +01:00
}
2014-12-15 16:42:34 +01:00
| T_VAR rterm
{
Expression *expr = $2;
BindToScope(expr, ScopeLocal);
2015-01-08 15:01:13 +01:00
$$ = new SetExpression(expr, OpSetLiteral, MakeLiteral(), @$);
2014-12-15 16:42:34 +01:00
}
| T_VAR rterm combined_set_op rterm
{
Expression *expr = $2;
BindToScope(expr, ScopeLocal);
2015-01-08 15:01:13 +01:00
$$ = new SetExpression(expr, $3, $4, @$);
2014-12-15 16:42:34 +01:00
}
2015-01-23 15:54:27 +01:00
| T_WHILE '(' rterm ')' rterm_scope
{
2015-03-07 14:47:54 +01:00
$5->MakeInline();
2015-01-23 15:54:27 +01:00
2015-03-07 14:47:54 +01:00
$$ = new WhileExpression($3, $5, @$);
2015-01-23 15:54:27 +01:00
}
2015-08-24 11:04:26 +02:00
| T_THROW rterm
{
$$ = new ThrowExpression($2, @$);
}
2015-01-08 09:33:24 +01:00
| rterm_side_effect
2012-05-31 16:04:51 +02:00
;
2014-03-23 11:27:40 +01:00
2014-04-11 13:51:14 +02:00
rterm_items: /* empty */
{
2014-11-09 19:48:28 +01:00
$$ = new std::vector<Expression *>();
2014-04-11 13:51:14 +02:00
}
| rterm_items_inner
2014-12-14 11:33:45 +01:00
| rterm_items_inner ','
| rterm_items_inner ',' newlines
| rterm_items_inner newlines
2014-03-23 11:27:40 +01:00
;
2013-03-14 12:17:46 +01:00
2014-04-11 13:51:14 +02:00
rterm_items_inner: rterm
2013-03-14 12:17:46 +01:00
{
2014-11-09 19:48:28 +01:00
$$ = new std::vector<Expression *>();
$$->push_back($1);
2013-03-14 12:17:46 +01:00
}
2014-04-11 13:51:14 +02:00
| rterm_items_inner arraysep rterm
2013-03-14 12:17:46 +01:00
{
2014-03-31 18:38:15 +02:00
$$ = $1;
2014-11-09 19:48:28 +01:00
$$->push_back($3);
2013-03-14 12:17:46 +01:00
}
2014-04-11 13:51:14 +02:00
;
2015-02-10 13:27:02 +01:00
rterm_array: '['
2014-04-11 13:51:14 +02:00
{
2015-02-10 13:27:02 +01:00
context->m_OpenBraces++;
}
newlines rterm_items ']'
{
context->m_OpenBraces--;
$$ = new ArrayExpression(*$4, @$);
delete $4;
2014-04-11 13:51:14 +02:00
}
2015-02-10 13:27:02 +01:00
| '['
2014-04-11 13:51:14 +02:00
{
2015-02-10 13:27:02 +01:00
context->m_OpenBraces++;
}
rterm_items ']'
{
$$ = new ArrayExpression(*$3, @$);
delete $3;
2014-03-31 18:38:15 +02:00
}
2013-03-14 12:17:46 +01:00
;
2015-02-10 13:27:02 +01:00
rterm_scope_require_side_effect: '{'
{
2015-09-23 16:37:21 +02:00
context->m_IgnoreNewlines.push(false);
2015-02-10 13:27:02 +01:00
context->m_OpenBraces++;
}
statements '}'
2015-01-08 10:30:34 +01:00
{
2015-02-10 13:27:02 +01:00
context->m_OpenBraces--;
2015-09-23 16:37:21 +02:00
context->m_IgnoreNewlines.pop();
2015-01-08 10:30:34 +01:00
std::vector<Expression *> dlist;
typedef std::pair<Expression *, EItemInfo> EListItem;
int num = 0;
2015-02-10 13:27:02 +01:00
BOOST_FOREACH(const EListItem& litem, *$3) {
2015-01-08 10:30:34 +01:00
if (!litem.second.SideEffect)
yyerror(&litem.second.DebugInfo, NULL, NULL, "Value computed is not used.");
dlist.push_back(litem.first);
num++;
}
2015-02-10 13:27:02 +01:00
delete $3;
2015-01-08 15:01:13 +01:00
$$ = new DictExpression(dlist, @$);
2015-01-08 10:30:34 +01:00
}
;
2015-02-10 13:27:02 +01:00
rterm_scope: '{'
2014-03-23 22:41:37 +01:00
{
2015-09-23 16:37:21 +02:00
context->m_IgnoreNewlines.push(false);
2015-02-10 13:27:02 +01:00
context->m_OpenBraces++;
}
statements '}'
{
context->m_OpenBraces--;
2015-09-23 16:37:21 +02:00
context->m_IgnoreNewlines.pop();
2015-01-08 10:30:34 +01:00
std::vector<Expression *> dlist;
typedef std::pair<Expression *, EItemInfo> EListItem;
int num = 0;
2015-02-10 13:27:02 +01:00
BOOST_FOREACH(const EListItem& litem, *$3) {
if (!litem.second.SideEffect && num != $3->size() - 1)
2015-01-08 10:30:34 +01:00
yyerror(&litem.second.DebugInfo, NULL, NULL, "Value computed is not used.");
dlist.push_back(litem.first);
num++;
}
2015-02-10 13:27:02 +01:00
delete $3;
2015-01-08 15:01:13 +01:00
$$ = new DictExpression(dlist, @$);
2014-03-23 22:41:37 +01:00
}
;
2015-02-26 13:50:25 +01:00
else_if_branch: T_ELSE T_IF '(' rterm ')' rterm_scope
{
2015-03-07 14:47:54 +01:00
$6->MakeInline();
2015-02-26 13:50:25 +01:00
2015-03-07 14:47:54 +01:00
$$ = new std::pair<Expression *, Expression *>($4, $6);
2015-02-26 13:50:25 +01:00
}
;
else_if_branches: /* empty */
{
$$ = new std::vector<std::pair<Expression *, Expression *> >();
}
| else_if_branches else_if_branch
{
$$ = $1;
$$->push_back(*$2);
delete $2;
}
;
2015-01-08 09:33:24 +01:00
rterm_side_effect: rterm '(' rterm_items ')'
{
2015-01-08 15:01:13 +01:00
$$ = new FunctionCallExpression($1, *$3, @$);
2015-01-08 09:33:24 +01:00
delete $3;
}
| identifier T_FOLLOWS rterm
{
DictExpression *aexpr = dynamic_cast<DictExpression *>($3);
if (aexpr)
aexpr->MakeInline();
std::vector<String> args;
2015-09-29 07:09:35 +02:00
args.push_back(*$1);
delete $1;
2015-01-08 09:33:24 +01:00
2015-01-08 15:01:13 +01:00
$$ = new FunctionExpression(args, new std::map<String, Expression *>(), $3, @$);
2015-01-08 09:33:24 +01:00
}
| '(' identifier_items ')' T_FOLLOWS rterm
{
DictExpression *aexpr = dynamic_cast<DictExpression *>($5);
if (aexpr)
aexpr->MakeInline();
2015-01-08 15:01:13 +01:00
$$ = new FunctionExpression(*$2, new std::map<String, Expression *>(), $5, @$);
2015-01-08 09:33:24 +01:00
delete $2;
}
2015-03-03 10:22:21 +01:00
| T_IF '(' rterm ')' rterm_scope else_if_branches
2015-01-08 09:33:24 +01:00
{
2015-03-07 14:47:54 +01:00
$5->MakeInline();
2015-01-08 09:33:24 +01:00
2015-03-03 10:22:21 +01:00
std::vector<std::pair<Expression *, Expression *> > ebranches = *$6;
delete $6;
Expression *afalse = NULL;
for (int i = ebranches.size() - 1; i >= 0; i--) {
const std::pair<Expression *, Expression *>& ebranch = ebranches[i];
afalse = new ConditionalExpression(ebranch.first, ebranch.second, afalse, @6);
}
2015-03-07 14:47:54 +01:00
$$ = new ConditionalExpression($3, $5, afalse, @$);
2015-01-08 09:33:24 +01:00
}
2015-02-26 13:50:25 +01:00
| T_IF '(' rterm ')' rterm_scope else_if_branches T_ELSE rterm_scope
2015-01-08 09:33:24 +01:00
{
2015-03-07 14:47:54 +01:00
$5->MakeInline();
2015-01-08 09:33:24 +01:00
2015-02-26 13:50:25 +01:00
std::vector<std::pair<Expression *, Expression *> > ebranches = *$6;
delete $6;
2015-03-07 14:47:54 +01:00
$8->MakeInline();
2015-02-26 13:50:25 +01:00
2015-03-07 14:47:54 +01:00
Expression *afalse = $8;
2015-02-26 13:50:25 +01:00
for (int i = ebranches.size() - 1; i >= 0; i--) {
const std::pair<Expression *, Expression *>& ebranch = ebranches[i];
afalse = new ConditionalExpression(ebranch.first, ebranch.second, afalse, @6);
}
2015-01-08 09:33:24 +01:00
2015-03-07 14:47:54 +01:00
$$ = new ConditionalExpression($3, $5, afalse, @$);
2015-01-08 09:33:24 +01:00
}
;
rterm_no_side_effect: T_STRING
2012-05-31 16:04:51 +02:00
{
2015-09-29 07:09:35 +02:00
$$ = MakeLiteral(*$1);
delete $1;
2012-05-31 16:04:51 +02:00
}
| T_NUMBER
{
2014-11-09 19:48:28 +01:00
$$ = MakeLiteral($1);
2012-05-31 16:04:51 +02:00
}
2014-12-10 09:04:49 +01:00
| T_BOOLEAN
{
$$ = MakeLiteral($1);
}
2012-06-01 16:49:33 +02:00
| T_NULL
{
2014-11-09 19:48:28 +01:00
$$ = MakeLiteral();
2012-06-01 16:49:33 +02:00
}
2014-12-14 11:33:45 +01:00
| rterm '.' T_IDENTIFIER %dprec 2
2013-03-14 12:17:46 +01:00
{
2015-09-29 07:09:35 +02:00
$$ = new IndexerExpression($1, MakeLiteral(*$3), @$);
delete $3;
2014-12-14 11:33:45 +01:00
}
| rterm '[' rterm ']'
{
2015-01-08 15:01:13 +01:00
$$ = new IndexerExpression($1, $3, @$);
2013-08-30 12:04:24 +02:00
}
| T_IDENTIFIER
{
2015-09-29 07:09:35 +02:00
$$ = new VariableExpression(*$1, @1);
delete $1;
2013-06-25 09:21:25 +02:00
}
2014-03-23 11:27:40 +01:00
| '!' rterm
2014-03-19 10:51:09 +01:00
{
2015-01-08 15:01:13 +01:00
$$ = new LogicalNegateExpression($2, @$);
2014-03-19 10:51:09 +01:00
}
2014-03-23 11:27:40 +01:00
| '~' rterm
2013-11-20 16:41:48 +01:00
{
2015-01-08 15:01:13 +01:00
$$ = new NegateExpression($2, @$);
2013-11-20 16:41:48 +01:00
}
2014-12-16 06:18:39 +01:00
| T_PLUS rterm %prec UNARY_PLUS
{
$$ = $2;
}
2014-11-23 23:19:46 +01:00
| T_MINUS rterm %prec UNARY_MINUS
{
2015-01-08 15:01:13 +01:00
$$ = new SubtractExpression(MakeLiteral(0), $2, @$);
2014-11-23 23:19:46 +01:00
}
2014-12-15 16:09:17 +01:00
| T_THIS
2014-12-14 11:33:45 +01:00
{
2014-12-15 16:09:17 +01:00
$$ = new GetScopeExpression(ScopeThis);
2014-12-14 11:33:45 +01:00
}
2015-01-16 13:04:34 +01:00
| T_GLOBALS
{
$$ = new GetScopeExpression(ScopeGlobal);
}
| T_LOCALS
{
$$ = new GetScopeExpression(ScopeLocal);
}
2014-04-11 13:51:14 +02:00
| rterm_array
2015-01-08 10:30:34 +01:00
| rterm_scope_require_side_effect
2013-06-25 09:21:25 +02:00
{
2014-12-15 12:57:40 +01:00
Expression *expr = $1;
2015-04-15 08:36:17 +02:00
BindToScope(expr, ScopeThis);
2014-12-15 12:57:40 +01:00
$$ = expr;
2013-06-25 09:21:25 +02:00
}
2014-03-31 18:38:15 +02:00
| '('
2013-06-25 09:21:25 +02:00
{
2015-03-11 09:55:38 +01:00
context->m_OpenBraces++;
2014-03-31 18:38:15 +02:00
}
rterm ')'
{
2015-03-11 09:55:38 +01:00
context->m_OpenBraces--;
2014-03-31 18:38:15 +02:00
$$ = $3;
2014-03-18 15:29:04 +01:00
}
2014-11-09 19:48:28 +01:00
| rterm T_LOGICAL_OR rterm { MakeRBinaryOp<LogicalOrExpression>(&$$, $1, $3, @1, @3); }
| rterm T_LOGICAL_AND rterm { MakeRBinaryOp<LogicalAndExpression>(&$$, $1, $3, @1, @3); }
| rterm T_BINARY_OR rterm { MakeRBinaryOp<BinaryOrExpression>(&$$, $1, $3, @1, @3); }
| rterm T_BINARY_AND rterm { MakeRBinaryOp<BinaryAndExpression>(&$$, $1, $3, @1, @3); }
| rterm T_IN rterm { MakeRBinaryOp<InExpression>(&$$, $1, $3, @1, @3); }
| rterm T_NOT_IN rterm { MakeRBinaryOp<NotInExpression>(&$$, $1, $3, @1, @3); }
| rterm T_EQUAL rterm { MakeRBinaryOp<EqualExpression>(&$$, $1, $3, @1, @3); }
| rterm T_NOT_EQUAL rterm { MakeRBinaryOp<NotEqualExpression>(&$$, $1, $3, @1, @3); }
| rterm T_LESS_THAN rterm { MakeRBinaryOp<LessThanExpression>(&$$, $1, $3, @1, @3); }
| rterm T_LESS_THAN_OR_EQUAL rterm { MakeRBinaryOp<LessThanOrEqualExpression>(&$$, $1, $3, @1, @3); }
| rterm T_GREATER_THAN rterm { MakeRBinaryOp<GreaterThanExpression>(&$$, $1, $3, @1, @3); }
| rterm T_GREATER_THAN_OR_EQUAL rterm { MakeRBinaryOp<GreaterThanOrEqualExpression>(&$$, $1, $3, @1, @3); }
| rterm T_SHIFT_LEFT rterm { MakeRBinaryOp<ShiftLeftExpression>(&$$, $1, $3, @1, @3); }
| rterm T_SHIFT_RIGHT rterm { MakeRBinaryOp<ShiftRightExpression>(&$$, $1, $3, @1, @3); }
| rterm T_PLUS rterm { MakeRBinaryOp<AddExpression>(&$$, $1, $3, @1, @3); }
| rterm T_MINUS rterm { MakeRBinaryOp<SubtractExpression>(&$$, $1, $3, @1, @3); }
| rterm T_MULTIPLY rterm { MakeRBinaryOp<MultiplyExpression>(&$$, $1, $3, @1, @3); }
| rterm T_DIVIDE_OP rterm { MakeRBinaryOp<DivideExpression>(&$$, $1, $3, @1, @3); }
2014-11-25 17:04:20 +01:00
| rterm T_MODULO rterm { MakeRBinaryOp<ModuloExpression>(&$$, $1, $3, @1, @3); }
| rterm T_XOR rterm { MakeRBinaryOp<XorExpression>(&$$, $1, $3, @1, @3); }
2014-11-22 12:21:28 +01:00
| T_FUNCTION '(' identifier_items ')' use_specifier rterm_scope
2014-03-30 15:04:53 +02:00
{
2015-03-07 14:47:54 +01:00
$6->MakeInline();
2014-03-30 15:04:53 +02:00
2015-03-07 14:47:54 +01:00
$$ = new FunctionExpression(*$3, $5, $6, @$);
2014-11-09 19:48:28 +01:00
delete $3;
2014-03-30 15:04:53 +02:00
}
2015-01-30 09:49:57 +01:00
| T_NULLARY_LAMBDA_BEGIN statements T_NULLARY_LAMBDA_END
{
std::vector<Expression *> dlist;
typedef std::pair<Expression *, EItemInfo> EListItem;
int num = 0;
BOOST_FOREACH(const EListItem& litem, *$2) {
if (!litem.second.SideEffect && num != $2->size() - 1)
yyerror(&litem.second.DebugInfo, NULL, NULL, "Value computed is not used.");
dlist.push_back(litem.first);
num++;
}
delete $2;
DictExpression *aexpr = new DictExpression(dlist, @$);
aexpr->MakeInline();
$$ = new FunctionExpression(std::vector<String>(), NULL, aexpr, @$);
}
2015-01-08 09:33:24 +01:00
;
2014-12-14 14:08:41 +01:00
2015-01-08 09:33:24 +01:00
rterm: rterm_side_effect
| rterm_no_side_effect
2013-06-25 09:21:25 +02:00
;
2014-04-05 12:56:56 +02:00
target_type_specifier: /* empty */
{
2015-09-29 07:09:35 +02:00
$$ = new String();
2014-04-05 12:56:56 +02:00
}
| T_TO identifier
{
$$ = $2;
}
;
2014-11-22 12:21:28 +01:00
use_specifier: /* empty */
{
$$ = NULL;
}
| T_USE '(' use_specifier_items ')'
{
$$ = $3;
}
;
use_specifier_items: use_specifier_item
{
$$ = new std::map<String, Expression *>();
$$->insert(*$1);
delete $1;
}
| use_specifier_items ',' use_specifier_item
{
$$ = $1;
$$->insert(*$3);
delete $3;
}
;
use_specifier_item: identifier
{
2015-09-29 07:09:35 +02:00
$$ = new std::pair<String, Expression *>(*$1, new VariableExpression(*$1, @1));
delete $1;
2014-11-22 12:21:28 +01:00
}
| identifier T_SET rterm
{
2015-09-29 07:09:35 +02:00
$$ = new std::pair<String, Expression *>(*$1, $3);
delete $1;
2014-11-22 12:21:28 +01:00
}
;
2014-11-02 07:22:00 +01:00
apply_for_specifier: /* empty */
2014-12-11 13:12:35 +01:00
| T_FOR '(' identifier T_FOLLOWS identifier T_IN rterm ')'
2014-11-04 11:01:00 +01:00
{
2015-09-29 07:09:35 +02:00
context->m_FKVar.top() = *$3;
delete $3;
2014-11-04 11:01:00 +01:00
2015-09-29 07:09:35 +02:00
context->m_FVVar.top() = *$5;
delete $5;
2014-11-04 11:01:00 +01:00
2014-11-25 09:40:32 +01:00
context->m_FTerm.top() = $7;
2014-11-04 11:01:00 +01:00
}
2014-12-11 13:12:35 +01:00
| T_FOR '(' identifier T_IN rterm ')'
2014-11-02 07:22:00 +01:00
{
2015-09-29 07:09:35 +02:00
context->m_FKVar.top() = *$3;
delete $3;
2014-11-02 07:22:00 +01:00
2014-11-25 09:40:32 +01:00
context->m_FVVar.top() = "";
2014-11-04 11:01:00 +01:00
2014-11-25 09:40:32 +01:00
context->m_FTerm.top() = $5;
2014-11-02 07:22:00 +01:00
}
;
2014-11-04 11:01:00 +01:00
optional_rterm: /* empty */
{
2014-11-09 19:48:28 +01:00
$$ = MakeLiteral();
2014-11-04 11:01:00 +01:00
}
| rterm
;
2014-03-28 13:25:40 +01:00
apply:
2014-03-18 11:44:09 +01:00
{
2014-11-25 09:40:32 +01:00
context->m_Apply.push(true);
context->m_SeenAssign.push(false);
2015-07-02 17:51:52 +02:00
context->m_SeenIgnore.push(false);
2014-11-25 09:40:32 +01:00
context->m_Assign.push(NULL);
context->m_Ignore.push(NULL);
context->m_FKVar.push("");
context->m_FVVar.push("");
context->m_FTerm.push(NULL);
2014-03-28 13:25:40 +01:00
}
2015-01-08 10:30:34 +01:00
T_APPLY identifier optional_rterm apply_for_specifier target_type_specifier use_specifier rterm_scope_require_side_effect
2014-03-28 13:25:40 +01:00
{
2014-11-25 09:40:32 +01:00
context->m_Apply.pop();
2014-03-28 13:25:40 +01:00
2015-09-29 07:09:35 +02:00
String type = *$3;
delete $3;
String target = *$6;
delete $6;
2014-03-18 11:44:09 +01:00
2014-04-05 12:56:56 +02:00
if (!ApplyRule::IsValidSourceType(type))
2014-12-10 15:06:09 +01:00
BOOST_THROW_EXCEPTION(ScriptError("'apply' cannot be used with type '" + type + "'", DebugInfoRange(@2, @3)));
2014-03-28 13:25:40 +01:00
2014-04-05 12:56:56 +02:00
if (!ApplyRule::IsValidTargetType(type, target)) {
if (target == "") {
std::vector<String> types = ApplyRule::GetTargetTypes(type);
String typeNames;
2014-05-11 06:00:34 +02:00
for (std::vector<String>::size_type i = 0; i < types.size(); i++) {
2014-04-05 12:56:56 +02:00
if (typeNames != "") {
if (i == types.size() - 1)
typeNames += " or ";
else
typeNames += ", ";
}
typeNames += "'" + types[i] + "'";
}
2014-12-10 15:06:09 +01:00
BOOST_THROW_EXCEPTION(ScriptError("'apply' target type is ambiguous (can be one of " + typeNames + "): use 'to' to specify a type", DebugInfoRange(@2, @3)));
2014-04-05 12:56:56 +02:00
} else
2014-12-10 15:06:09 +01:00
BOOST_THROW_EXCEPTION(ScriptError("'apply' target type '" + target + "' is invalid", DebugInfoRange(@2, @5)));
2014-04-05 12:56:56 +02:00
}
2015-03-07 14:47:54 +01:00
$8->MakeInline();
2014-03-20 13:02:02 +01:00
2015-01-29 12:38:25 +01:00
bool seen_assign = context->m_SeenAssign.top();
2014-11-25 09:40:32 +01:00
context->m_SeenAssign.pop();
2014-11-01 06:25:58 +01:00
2015-01-29 12:38:25 +01:00
// assign && !ignore
if (!seen_assign && !context->m_FTerm.top())
BOOST_THROW_EXCEPTION(ScriptError("'apply' is missing 'assign'/'for'", DebugInfoRange(@2, @3)));
2014-11-25 09:40:32 +01:00
Expression *ignore = context->m_Ignore.top();
context->m_Ignore.pop();
2014-11-01 06:25:58 +01:00
2015-01-29 12:38:25 +01:00
Expression *assign;
if (!seen_assign)
assign = MakeLiteral(true);
else
assign = context->m_Assign.top();
2014-11-25 09:40:32 +01:00
context->m_Assign.pop();
2014-03-30 15:04:53 +02:00
2014-11-10 12:05:45 +01:00
Expression *filter;
if (ignore) {
Expression *rex = new LogicalNegateExpression(ignore, DebugInfoRange(@2, @5));
filter = new LogicalAndExpression(assign, rex, DebugInfoRange(@2, @5));
} else
filter = assign;
2014-11-25 09:40:32 +01:00
String fkvar = context->m_FKVar.top();
context->m_FKVar.pop();
2014-11-04 11:01:00 +01:00
2014-11-25 09:40:32 +01:00
String fvvar = context->m_FVVar.top();
context->m_FVVar.pop();
2014-11-02 07:22:00 +01:00
2014-11-25 09:40:32 +01:00
Expression *fterm = context->m_FTerm.top();
context->m_FTerm.pop();
2014-11-02 07:22:00 +01:00
2015-08-28 17:58:29 +02:00
$$ = new ApplyExpression(type, target, $4, filter, context->GetPackage(), fkvar, fvvar, fterm, $7, $8, DebugInfoRange(@2, @7));
2014-03-18 11:44:09 +01:00
}
2014-03-31 18:38:15 +02:00
;
newlines: T_NEWLINE
2014-11-22 23:02:12 +01:00
| T_NEWLINE newlines
2014-03-31 18:38:15 +02:00
;
/* required separator */
sep: ',' newlines
| ','
| ';' newlines
| ';'
| newlines
;
2014-04-11 13:51:14 +02:00
arraysep: ',' newlines
| ','
;
2012-05-31 08:45:02 +02:00
%%