4 /******************************************************************************
6 * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU General Public License *
10 * as published by the Free Software Foundation; either version 2 *
11 * of the License, or (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the Free Software Foundation *
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
21 ******************************************************************************/
23 #include "config/i2-config.hpp"
24 #include "config/configitembuilder.hpp"
25 #include "config/configtype.hpp"
26 #include "config/configcompiler.hpp"
27 #include "config/configcompilercontext.hpp"
28 #include "config/typerule.hpp"
29 #include "config/typerulelist.hpp"
30 #include "config/expression.hpp"
31 #include "config/applyrule.hpp"
32 #include "config/objectrule.hpp"
33 #include "base/value.hpp"
34 #include "base/utility.hpp"
35 #include "base/array.hpp"
36 #include "base/scriptvariable.hpp"
37 #include "base/exception.hpp"
38 #include "base/dynamictype.hpp"
39 #include "base/configerror.hpp"
42 #include <boost/foreach.hpp>
44 #define YYLTYPE icinga::DebugInfo
45 #define YYERROR_VERBOSE
47 #define YYLLOC_DEFAULT(Current, Rhs, N) \
50 (Current).Path = YYRHSLOC(Rhs, 1).Path; \
51 (Current).FirstLine = YYRHSLOC(Rhs, 1).FirstLine; \
52 (Current).FirstColumn = YYRHSLOC(Rhs, 1).FirstColumn; \
53 (Current).LastLine = YYRHSLOC(Rhs, N).LastLine; \
54 (Current).LastColumn = YYRHSLOC(Rhs, N).LastColumn; \
56 (Current).Path = YYRHSLOC(Rhs, 0).Path; \
57 (Current).FirstLine = (Current).LastLine = \
58 YYRHSLOC(Rhs, 0).LastLine; \
59 (Current).FirstColumn = (Current).LastColumn = \
60 YYRHSLOC(Rhs, 0).LastColumn; \
64 #define YY_LOCATION_PRINT(file, loc) \
66 std::ostringstream msgbuf; \
68 std::string str = msgbuf.str(); \
69 fputs(str.c_str(), file); \
72 using namespace icinga;
74 int ignore_newlines = 0;
76 static void MakeRBinaryOp(Value** result, Expression::OpCallback& op, Value *left, Value *right, DebugInfo& diLeft, DebugInfo& diRight)
78 *result = new Value(make_shared<Expression>(op, *left, *right, DebugInfoRange(diLeft, diRight)));
91 %parse-param { ConfigCompiler *context }
92 %lex-param { void *scanner }
97 icinga::Value *variant;
98 icinga::Expression::OpCallback op;
99 icinga::TypeSpecifier type;
100 std::vector<String> *slist;
104 %token T_NEWLINE "new-line"
105 %token <text> T_STRING
106 %token <text> T_STRING_ANGLE
107 %token <num> T_NUMBER
109 %token <text> T_IDENTIFIER
111 %token <op> T_SET "= (T_SET)"
112 %token <op> T_SET_PLUS "+= (T_SET_PLUS)"
113 %token <op> T_SET_MINUS "-= (T_SET_MINUS)"
114 %token <op> T_SET_MULTIPLY "*= (T_SET_MULTIPLY)"
115 %token <op> T_SET_DIVIDE "/= (T_SET_DIVIDE)"
117 %token <op> T_SHIFT_LEFT "<< (T_SHIFT_LEFT)"
118 %token <op> T_SHIFT_RIGHT ">> (T_SHIFT_RIGHT)"
119 %token <op> T_EQUAL "== (T_EQUAL)"
120 %token <op> T_NOT_EQUAL "!= (T_NOT_EQUAL)"
121 %token <op> T_IN "in (T_IN)"
122 %token <op> T_NOT_IN "!in (T_NOT_IN)"
123 %token <op> T_LOGICAL_AND "&& (T_LOGICAL_AND)"
124 %token <op> T_LOGICAL_OR "|| (T_LOGICAL_OR)"
125 %token <op> T_LESS_THAN_OR_EQUAL "<= (T_LESS_THAN_OR_EQUAL)"
126 %token <op> T_GREATER_THAN_OR_EQUAL ">= (T_GREATER_THAN_OR_EQUAL)"
127 %token <op> T_PLUS "+ (T_PLUS)"
128 %token <op> T_MINUS "- (T_MINUS)"
129 %token <op> T_MULTIPLY "* (T_MULTIPLY)"
130 %token <op> T_DIVIDE_OP "/ (T_DIVIDE_OP)"
131 %token <op> T_BINARY_AND "& (T_BINARY_AND)"
132 %token <op> T_BINARY_OR "| (T_BINARY_OR)"
133 %token <op> T_LESS_THAN "< (T_LESS_THAN)"
134 %token <op> T_GREATER_THAN "> (T_GREATER_THAN)"
136 %token T_CONST "const (T_CONST)"
137 %token <type> T_TYPE_DICTIONARY "dictionary (T_TYPE_DICTIONARY)"
138 %token <type> T_TYPE_ARRAY "array (T_TYPE_ARRAY)"
139 %token <type> T_TYPE_NUMBER "number (T_TYPE_NUMBER)"
140 %token <type> T_TYPE_STRING "string (T_TYPE_STRING)"
141 %token <type> T_TYPE_SCALAR "scalar (T_TYPE_SCALAR)"
142 %token <type> T_TYPE_ANY "any (T_TYPE_ANY)"
143 %token <type> T_TYPE_NAME "name (T_TYPE_NAME)"
144 %token T_VALIDATOR "%validator (T_VALIDATOR)"
145 %token T_REQUIRE "%require (T_REQUIRE)"
146 %token T_ATTRIBUTE "%attribute (T_ATTRIBUTE)"
147 %token T_TYPE "type (T_TYPE)"
148 %token T_OBJECT "object (T_OBJECT)"
149 %token T_TEMPLATE "template (T_TEMPLATE)"
150 %token T_INCLUDE "include (T_INCLUDE)"
151 %token T_INCLUDE_RECURSIVE "include_recursive (T_INCLUDE_RECURSIVE)"
152 %token T_LIBRARY "library (T_LIBRARY)"
153 %token T_INHERITS "inherits (T_INHERITS)"
154 %token T_APPLY "apply (T_APPLY)"
155 %token T_TO "to (T_TO)"
156 %token T_WHERE "where (T_WHERE)"
157 %token T_IMPORT "import (T_IMPORT)"
158 %token T_ASSIGN "assign (T_ASSIGN)"
159 %token T_IGNORE "ignore (T_IGNORE)"
160 %token T_FUNCTION "function (T_FUNCTION)"
161 %token T_RETURN "return (T_RETURN)"
162 %token T_FOR "for (T_FOR)"
164 %type <text> identifier
165 %type <array> rterm_items
166 %type <array> rterm_items_inner
167 %type <array> identifier_items
168 %type <array> identifier_items_inner
169 %type <array> lterm_items
170 %type <array> lterm_items_inner
171 %type <variant> typerulelist
172 %type <op> lbinary_op
174 %type <variant> rterm
175 %type <variant> rterm_array
176 %type <variant> rterm_scope
177 %type <variant> lterm
178 %type <variant> object
179 %type <variant> apply
180 %type <text> target_type_specifier
188 %left T_EQUAL T_NOT_EQUAL
189 %left T_LESS_THAN T_LESS_THAN_OR_EQUAL T_GREATER_THAN T_GREATER_THAN_OR_EQUAL
190 %left T_SHIFT_LEFT T_SHIFT_RIGHT
192 %left T_MULTIPLY T_DIVIDE_OP
198 int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
200 void yyerror(YYLTYPE *locp, ConfigCompiler *, const char *err)
202 std::ostringstream message;
203 message << *locp << ": " << err;
204 ConfigCompilerContext::GetInstance()->AddMessage(true, message.str(), *locp);
207 int yyparse(ConfigCompiler *context);
209 static std::stack<bool> m_Abstract;
211 static std::stack<TypeRuleList::Ptr> m_RuleLists;
212 static ConfigType::Ptr m_Type;
214 static Dictionary::Ptr m_ModuleScope;
216 static std::stack<bool> m_Apply;
217 static std::stack<bool> m_ObjectAssign;
218 static std::stack<bool> m_SeenAssign;
219 static std::stack<Expression::Ptr> m_Assign;
220 static std::stack<Expression::Ptr> m_Ignore;
221 static std::stack<String> m_FVar;
222 static std::stack<Expression::Ptr> m_FTerm;
224 void ConfigCompiler::Compile(void)
226 m_ModuleScope = make_shared<Dictionary>();
228 m_Abstract = std::stack<bool>();
229 m_RuleLists = std::stack<TypeRuleList::Ptr>();
231 m_Apply = std::stack<bool>();
232 m_ObjectAssign = std::stack<bool>();
233 m_SeenAssign = std::stack<bool>();
234 m_Assign = std::stack<Expression::Ptr>();
235 m_Ignore = std::stack<Expression::Ptr>();
236 m_FVar = std::stack<String>();
237 m_FTerm = std::stack<Expression::Ptr>();
241 } catch (const ConfigError& ex) {
242 const DebugInfo *di = boost::get_error_info<errinfo_debuginfo>(ex);
243 ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo());
244 } catch (const std::exception& ex) {
245 ConfigCompilerContext::GetInstance()->AddMessage(true, DiagnosticInformation(ex));
249 #define scanner (context->GetScanner())
254 statements: /* empty */
255 | statements statement
258 statement: type | include | include_recursive | library | constant
264 Expression::Ptr aexpr = *$1;
265 aexpr->Evaluate(m_ModuleScope);
270 include: T_INCLUDE rterm sep
272 Expression::Ptr aexpr = *$2;
275 context->HandleInclude(aexpr->Evaluate(m_ModuleScope), false, DebugInfoRange(@1, @2));
277 | T_INCLUDE T_STRING_ANGLE
279 context->HandleInclude($2, true, DebugInfoRange(@1, @2));
284 include_recursive: T_INCLUDE_RECURSIVE rterm
286 Expression::Ptr aexpr = *$2;
289 context->HandleIncludeRecursive(aexpr->Evaluate(m_ModuleScope), "*.conf", DebugInfoRange(@1, @2));
291 | T_INCLUDE_RECURSIVE rterm ',' rterm
293 Expression::Ptr aexpr1 = *$2;
296 Expression::Ptr aexpr2 = *$4;
299 context->HandleIncludeRecursive(aexpr1->Evaluate(m_ModuleScope), aexpr2->Evaluate(m_ModuleScope), DebugInfoRange(@1, @4));
303 library: T_LIBRARY T_STRING sep
305 context->HandleLibrary($2);
310 constant: T_CONST identifier T_SET rterm sep
312 Expression::Ptr aexpr = *$4;
315 ScriptVariable::Ptr sv = ScriptVariable::Set($2, aexpr->Evaluate(m_ModuleScope));
316 sv->SetConstant(true);
322 identifier: T_IDENTIFIER
329 type: T_TYPE identifier
331 String name = String($2);
334 m_Type = ConfigType::GetByName(name);
337 m_Type = make_shared<ConfigType>(name, DebugInfoRange(@1, @2));
341 type_inherits_specifier typerulelist sep
343 TypeRuleList::Ptr ruleList = *$5;
346 m_Type->GetRuleList()->AddRules(ruleList);
347 m_Type->GetRuleList()->AddRequires(ruleList);
349 String validator = ruleList->GetValidator();
350 if (!validator.IsEmpty())
351 m_Type->GetRuleList()->SetValidator(validator);
357 m_RuleLists.push(make_shared<TypeRuleList>());
362 $$ = new Value(m_RuleLists.top());
367 typerules: typerules_inner
368 | typerules_inner sep
370 typerules_inner: /* empty */
372 | typerules_inner sep typerule
375 typerule: T_REQUIRE T_STRING
377 m_RuleLists.top()->AddRequire($2);
380 | T_VALIDATOR T_STRING
382 m_RuleLists.top()->SetValidator($2);
385 | T_ATTRIBUTE type T_STRING
387 TypeRule rule($2, String(), $3, TypeRuleList::Ptr(), DebugInfoRange(@1, @3));
390 m_RuleLists.top()->AddRule(rule);
392 | T_ATTRIBUTE T_TYPE_NAME '(' identifier ')' T_STRING
394 TypeRule rule($2, $4, $6, TypeRuleList::Ptr(), DebugInfoRange(@1, @6));
398 m_RuleLists.top()->AddRule(rule);
400 | T_ATTRIBUTE type T_STRING typerulelist
402 TypeRule rule($2, String(), $3, *$4, DebugInfoRange(@1, @4));
405 m_RuleLists.top()->AddRule(rule);
409 type_inherits_specifier: /* empty */
410 | T_INHERITS identifier
412 m_Type->SetParent($2);
417 type: T_TYPE_DICTIONARY
431 m_Abstract.push(false);
432 m_ObjectAssign.push(true);
433 m_SeenAssign.push(false);
434 m_Assign.push(make_shared<Expression>(&Expression::OpLiteral, false, DebugInfo()));
435 m_Ignore.push(make_shared<Expression>(&Expression::OpLiteral, false, DebugInfo()));
437 object_declaration identifier rterm rterm_scope
439 m_ObjectAssign.pop();
441 Array::Ptr args = make_shared<Array>();
443 args->Add(m_Abstract.top());
453 Expression::Ptr exprl = *$5;
457 if (m_SeenAssign.top() && !ObjectRule::IsValidSourceType(type))
458 BOOST_THROW_EXCEPTION(ConfigError("object rule 'assign' cannot be used for type '" + type + "'") << errinfo_debuginfo(DebugInfoRange(@2, @3)));
462 Expression::Ptr rex = make_shared<Expression>(&Expression::OpLogicalNegate, m_Ignore.top(), DebugInfoRange(@2, @5));
465 Expression::Ptr filter = make_shared<Expression>(&Expression::OpLogicalAnd, m_Assign.top(), rex, DebugInfoRange(@2, @5));
470 args->Add(context->GetZone());
472 $$ = new Value(make_shared<Expression>(&Expression::OpObject, args, exprl, DebugInfoRange(@2, @5)));
476 object_declaration: T_OBJECT
479 m_Abstract.top() = true;
482 identifier_items: identifier_items_inner
486 | identifier_items_inner ','
492 identifier_items_inner: /* empty */
502 | identifier_items_inner ',' identifier
524 lterm_items: /* empty */
532 | lterm_items_inner sep
537 lterm_items_inner: lterm
543 | lterm_items_inner sep lterm
555 lterm: identifier lbinary_op rterm
557 Expression::Ptr aindex = make_shared<Expression>(&Expression::OpLiteral, $1, @1);
560 $$ = new Value(make_shared<Expression>($2, aindex, *$3, DebugInfoRange(@1, @3)));
563 | identifier '[' rterm ']' lbinary_op rterm
565 Expression::Ptr subexpr = make_shared<Expression>($5, *$3, *$6, DebugInfoRange(@1, @6));
569 Array::Ptr subexprl = make_shared<Array>();
570 subexprl->Add(subexpr);
572 Expression::Ptr aindex = make_shared<Expression>(&Expression::OpLiteral, $1, @1);
575 Expression::Ptr expr = make_shared<Expression>(&Expression::OpDict, subexprl, DebugInfoRange(@1, @6));
576 $$ = new Value(make_shared<Expression>(&Expression::OpSetPlus, aindex, expr, DebugInfoRange(@1, @6)));
578 | identifier '.' T_IDENTIFIER lbinary_op rterm
580 Expression::Ptr aindex = make_shared<Expression>(&Expression::OpLiteral, $3, @3);
581 Expression::Ptr subexpr = make_shared<Expression>($4, aindex, *$5, DebugInfoRange(@1, @5));
585 Array::Ptr subexprl = make_shared<Array>();
586 subexprl->Add(subexpr);
588 Expression::Ptr aindexl = make_shared<Expression>(&Expression::OpLiteral, $1, @1);
591 Expression::Ptr expr = make_shared<Expression>(&Expression::OpDict, subexprl, DebugInfoRange(@1, @5));
592 $$ = new Value(make_shared<Expression>(&Expression::OpSetPlus, aindexl, expr, DebugInfoRange(@1, @5)));
596 Expression::Ptr avar = make_shared<Expression>(&Expression::OpVariable, "type", DebugInfoRange(@1, @2));
597 $$ = new Value(make_shared<Expression>(&Expression::OpImport, avar, *$2, DebugInfoRange(@1, @2)));
600 | T_ASSIGN T_WHERE rterm
602 if ((m_Apply.empty() || !m_Apply.top()) && (m_ObjectAssign.empty() || !m_ObjectAssign.top()))
603 BOOST_THROW_EXCEPTION(ConfigError("'assign' keyword not valid in this context."));
605 m_SeenAssign.top() = true;
607 m_Assign.top() = make_shared<Expression>(&Expression::OpLogicalOr, m_Assign.top(), *$3, DebugInfoRange(@1, @3));
610 $$ = new Value(make_shared<Expression>(&Expression::OpLiteral, Empty, DebugInfoRange(@1, @3)));
612 | T_IGNORE T_WHERE rterm
614 if ((m_Apply.empty() || !m_Apply.top()) && (m_ObjectAssign.empty() || !m_ObjectAssign.top()))
615 BOOST_THROW_EXCEPTION(ConfigError("'ignore' keyword not valid in this context."));
617 m_Ignore.top() = make_shared<Expression>(&Expression::OpLogicalOr, m_Ignore.top(), *$3, DebugInfoRange(@1, @3));
620 $$ = new Value(make_shared<Expression>(&Expression::OpLiteral, Empty, DebugInfoRange(@1, @3)));
624 Expression::Ptr aname = make_shared<Expression>(&Expression::OpLiteral, "__result", @1);
625 $$ = new Value(make_shared<Expression>(&Expression::OpSet, aname, *$2, DebugInfoRange(@1, @2)));
643 rterm_items: /* empty */
651 | rterm_items_inner arraysep
657 rterm_items_inner: rterm
663 | rterm_items_inner arraysep rterm
671 rterm_array: '[' newlines rterm_items newlines ']'
673 $$ = new Value(make_shared<Expression>(&Expression::OpArray, Array::Ptr($3), DebugInfoRange(@1, @5)));
675 | '[' newlines rterm_items ']'
677 $$ = new Value(make_shared<Expression>(&Expression::OpArray, Array::Ptr($3), DebugInfoRange(@1, @4)));
679 | '[' rterm_items newlines ']'
681 $$ = new Value(make_shared<Expression>(&Expression::OpArray, Array::Ptr($2), DebugInfoRange(@1, @4)));
683 | '[' rterm_items ']'
685 $$ = new Value(make_shared<Expression>(&Expression::OpArray, Array::Ptr($2), DebugInfoRange(@1, @3)));
689 rterm_scope: '{' newlines lterm_items newlines '}'
691 $$ = new Value(make_shared<Expression>(&Expression::OpDict, Array::Ptr($3), DebugInfoRange(@1, @5)));
693 | '{' newlines lterm_items '}'
695 $$ = new Value(make_shared<Expression>(&Expression::OpDict, Array::Ptr($3), DebugInfoRange(@1, @4)));
697 | '{' lterm_items newlines '}'
699 $$ = new Value(make_shared<Expression>(&Expression::OpDict, Array::Ptr($2), DebugInfoRange(@1, @4)));
701 | '{' lterm_items '}'
703 $$ = new Value(make_shared<Expression>(&Expression::OpDict, Array::Ptr($2), DebugInfoRange(@1, @3)));
709 $$ = new Value(make_shared<Expression>(&Expression::OpLiteral, $1, @1));
714 $$ = new Value(make_shared<Expression>(&Expression::OpLiteral, $1, @1));
718 $$ = new Value(make_shared<Expression>(&Expression::OpLiteral, Empty, @1));
720 | rterm '.' T_IDENTIFIER
722 $$ = new Value(make_shared<Expression>(&Expression::OpIndexer, *$1, make_shared<Expression>(&Expression::OpLiteral, $3, @3), DebugInfoRange(@1, @3)));
726 | rterm '(' rterm_items ')'
728 Array::Ptr arguments = Array::Ptr($3);
729 $$ = new Value(make_shared<Expression>(&Expression::OpFunctionCall, *$1, make_shared<Expression>(&Expression::OpLiteral, arguments, @3), DebugInfoRange(@1, @4)));
734 $$ = new Value(make_shared<Expression>(&Expression::OpVariable, $1, @1));
739 $$ = new Value(make_shared<Expression>(&Expression::OpLogicalNegate, *$2, DebugInfoRange(@1, @2)));
744 $$ = new Value(make_shared<Expression>(&Expression::OpNegate, *$2, DebugInfoRange(@1, @2)));
747 | rterm '[' rterm ']'
749 $$ = new Value(make_shared<Expression>(&Expression::OpIndexer, *$1, *$3, DebugInfoRange(@1, @4)));
770 | rterm T_LOGICAL_OR rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
771 | rterm T_LOGICAL_AND rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
772 | rterm T_BINARY_OR rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
773 | rterm T_BINARY_AND rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
774 | rterm T_IN rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
775 | rterm T_NOT_IN rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
776 | rterm T_EQUAL rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
777 | rterm T_NOT_EQUAL rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
778 | rterm T_LESS_THAN rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
779 | rterm T_LESS_THAN_OR_EQUAL rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
780 | rterm T_GREATER_THAN rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
781 | rterm T_GREATER_THAN_OR_EQUAL rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
782 | rterm T_SHIFT_LEFT rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
783 | rterm T_SHIFT_RIGHT rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
784 | rterm T_PLUS rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
785 | rterm T_MINUS rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
786 | rterm T_MULTIPLY rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
787 | rterm T_DIVIDE_OP rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
788 | T_FUNCTION identifier '(' identifier_items ')' rterm_scope
790 Array::Ptr arr = make_shared<Array>();
795 Expression::Ptr aexpr = *$6;
800 $$ = new Value(make_shared<Expression>(&Expression::OpFunction, arr, Array::Ptr($4), DebugInfoRange(@1, @6)));
802 | T_FUNCTION '(' identifier_items ')' rterm_scope
804 Array::Ptr arr = make_shared<Array>();
808 Expression::Ptr aexpr = *$5;
813 $$ = new Value(make_shared<Expression>(&Expression::OpFunction, arr, Array::Ptr($3), DebugInfoRange(@1, @5)));
815 | T_FOR '(' identifier T_IN rterm ')' rterm_scope
817 Array::Ptr arr = make_shared<Array>();
822 Expression::Ptr aexpr = *$5;
826 Expression::Ptr ascope = *$7;
829 $$ = new Value(make_shared<Expression>(&Expression::OpFor, arr, ascope, DebugInfoRange(@1, @7)));
833 target_type_specifier: /* empty */
843 apply_for_specifier: /* empty */
844 | T_FOR '(' identifier T_IN rterm ')'
857 m_SeenAssign.push(false);
858 m_Assign.push(make_shared<Expression>(&Expression::OpLiteral, false, DebugInfo()));
859 m_Ignore.push(make_shared<Expression>(&Expression::OpLiteral, false, DebugInfo()));
861 m_FTerm.push(Expression::Ptr());
863 T_APPLY identifier rterm apply_for_specifier target_type_specifier rterm
869 Expression::Ptr aname = *$4;
874 if (!ApplyRule::IsValidSourceType(type))
875 BOOST_THROW_EXCEPTION(ConfigError("'apply' cannot be used with type '" + type + "'") << errinfo_debuginfo(DebugInfoRange(@2, @3)));
877 if (!ApplyRule::IsValidTargetType(type, target)) {
879 std::vector<String> types = ApplyRule::GetTargetTypes(type);
882 for (std::vector<String>::size_type i = 0; i < types.size(); i++) {
883 if (typeNames != "") {
884 if (i == types.size() - 1)
890 typeNames += "'" + types[i] + "'";
893 BOOST_THROW_EXCEPTION(ConfigError("'apply' target type is ambiguous (can be one of " + typeNames + "): use 'to' to specify a type") << errinfo_debuginfo(DebugInfoRange(@2, @3)));
895 BOOST_THROW_EXCEPTION(ConfigError("'apply' target type '" + target + "' is invalid") << errinfo_debuginfo(DebugInfoRange(@2, @5)));
898 Expression::Ptr exprl = *$7;
904 if (!m_SeenAssign.top())
905 BOOST_THROW_EXCEPTION(ConfigError("'apply' is missing 'assign'") << errinfo_debuginfo(DebugInfoRange(@2, @3)));
909 Expression::Ptr rex = make_shared<Expression>(&Expression::OpLogicalNegate, m_Ignore.top(), DebugInfoRange(@2, @5));
912 Expression::Ptr filter = make_shared<Expression>(&Expression::OpLogicalAnd, m_Assign.top(), rex, DebugInfoRange(@2, @5));
915 String fvar = m_FVar.top();
918 Expression::Ptr fterm = m_FTerm.top();
921 Array::Ptr args = make_shared<Array>();
929 $$ = new Value(make_shared<Expression>(&Expression::OpApply, args, exprl, DebugInfoRange(@2, @5)));
937 /* required separator */
945 arraysep: ',' newlines