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/configerror.hpp"
29 #include "config/typerule.hpp"
30 #include "config/typerulelist.hpp"
31 #include "config/aexpression.hpp"
32 #include "config/applyrule.hpp"
33 #include "config/objectrule.hpp"
34 #include "config/aexpression.hpp"
35 #include "base/value.hpp"
36 #include "base/utility.hpp"
37 #include "base/array.hpp"
38 #include "base/scriptvariable.hpp"
39 #include "base/exception.hpp"
40 #include "base/dynamictype.hpp"
43 #include <boost/foreach.hpp>
45 #define YYLTYPE icinga::DebugInfo
46 #define YYERROR_VERBOSE
48 #define YYLLOC_DEFAULT(Current, Rhs, N) \
51 (Current).Path = YYRHSLOC(Rhs, 1).Path; \
52 (Current).FirstLine = YYRHSLOC(Rhs, 1).FirstLine; \
53 (Current).FirstColumn = YYRHSLOC(Rhs, 1).FirstColumn; \
54 (Current).LastLine = YYRHSLOC(Rhs, N).LastLine; \
55 (Current).LastColumn = YYRHSLOC(Rhs, N).LastColumn; \
57 (Current).Path = YYRHSLOC(Rhs, 0).Path; \
58 (Current).FirstLine = (Current).LastLine = \
59 YYRHSLOC(Rhs, 0).LastLine; \
60 (Current).FirstColumn = (Current).LastColumn = \
61 YYRHSLOC(Rhs, 0).LastColumn; \
65 #define YY_LOCATION_PRINT(file, loc) \
67 std::ostringstream msgbuf; \
69 std::string str = msgbuf.str(); \
70 fputs(str.c_str(), file); \
73 using namespace icinga;
75 int ignore_newlines = 0;
77 static void MakeRBinaryOp(Value** result, AExpression::OpCallback& op, Value *left, Value *right, DebugInfo& diLeft, DebugInfo& diRight)
79 *result = new Value(make_shared<AExpression>(op, *left, *right, DebugInfoRange(diLeft, diRight)));
92 %parse-param { ConfigCompiler *context }
93 %lex-param { void *scanner }
98 icinga::Value *variant;
99 icinga::AExpression::OpCallback op;
100 icinga::TypeSpecifier type;
101 std::vector<String> *slist;
105 %token T_NEWLINE "new-line"
106 %token <text> T_STRING
107 %token <text> T_STRING_ANGLE
108 %token <num> T_NUMBER
110 %token <text> T_IDENTIFIER
112 %token <op> T_SET "= (T_SET)"
113 %token <op> T_SET_PLUS "+= (T_SET_PLUS)"
114 %token <op> T_SET_MINUS "-= (T_SET_MINUS)"
115 %token <op> T_SET_MULTIPLY "*= (T_SET_MULTIPLY)"
116 %token <op> T_SET_DIVIDE "/= (T_SET_DIVIDE)"
118 %token <op> T_SHIFT_LEFT "<< (T_SHIFT_LEFT)"
119 %token <op> T_SHIFT_RIGHT ">> (T_SHIFT_RIGHT)"
120 %token <op> T_EQUAL "== (T_EQUAL)"
121 %token <op> T_NOT_EQUAL "!= (T_NOT_EQUAL)"
122 %token <op> T_IN "in (T_IN)"
123 %token <op> T_NOT_IN "!in (T_NOT_IN)"
124 %token <op> T_LOGICAL_AND "&& (T_LOGICAL_AND)"
125 %token <op> T_LOGICAL_OR "|| (T_LOGICAL_OR)"
126 %token <op> T_LESS_THAN_OR_EQUAL "<= (T_LESS_THAN_OR_EQUAL)"
127 %token <op> T_GREATER_THAN_OR_EQUAL ">= (T_GREATER_THAN_OR_EQUAL)"
128 %token <op> T_PLUS "+ (T_PLUS)"
129 %token <op> T_MINUS "- (T_MINUS)"
130 %token <op> T_MULTIPLY "* (T_MULTIPLY)"
131 %token <op> T_DIVIDE_OP "/ (T_DIVIDE_OP)"
132 %token <op> T_BINARY_AND "& (T_BINARY_AND)"
133 %token <op> T_BINARY_OR "| (T_BINARY_OR)"
134 %token <op> T_LESS_THAN "< (T_LESS_THAN)"
135 %token <op> T_GREATER_THAN "> (T_GREATER_THAN)"
137 %token T_CONST "const (T_CONST)"
138 %token <type> T_TYPE_DICTIONARY "dictionary (T_TYPE_DICTIONARY)"
139 %token <type> T_TYPE_ARRAY "array (T_TYPE_ARRAY)"
140 %token <type> T_TYPE_NUMBER "number (T_TYPE_NUMBER)"
141 %token <type> T_TYPE_STRING "string (T_TYPE_STRING)"
142 %token <type> T_TYPE_SCALAR "scalar (T_TYPE_SCALAR)"
143 %token <type> T_TYPE_ANY "any (T_TYPE_ANY)"
144 %token <type> T_TYPE_NAME "name (T_TYPE_NAME)"
145 %token T_VALIDATOR "%validator (T_VALIDATOR)"
146 %token T_REQUIRE "%require (T_REQUIRE)"
147 %token T_ATTRIBUTE "%attribute (T_ATTRIBUTE)"
148 %token T_TYPE "type (T_TYPE)"
149 %token T_OBJECT "object (T_OBJECT)"
150 %token T_TEMPLATE "template (T_TEMPLATE)"
151 %token T_INCLUDE "include (T_INCLUDE)"
152 %token T_INCLUDE_RECURSIVE "include_recursive (T_INCLUDE_RECURSIVE)"
153 %token T_LIBRARY "library (T_LIBRARY)"
154 %token T_INHERITS "inherits (T_INHERITS)"
155 %token T_PARTIAL "partial (T_PARTIAL)"
156 %token T_APPLY "apply (T_APPLY)"
157 %token T_TO "to (T_TO)"
158 %token T_WHERE "where (T_WHERE)"
159 %token T_IMPORT "import (T_IMPORT)"
160 %token T_ASSIGN "assign (T_ASSIGN)"
161 %token T_IGNORE "ignore (T_IGNORE)"
162 %token T_FUNCTION "function (T_FUNCTION)"
163 %token T_RETURN "return (T_RETURN)"
164 %token T_ZONE "zone (T_ZONE)"
165 %token T_FOR "for (T_FOR)"
167 %type <text> identifier
168 %type <array> rterm_items
169 %type <array> rterm_items_inner
170 %type <array> identifier_items
171 %type <array> identifier_items_inner
172 %type <array> lterm_items
173 %type <array> lterm_items_inner
174 %type <variant> typerulelist
175 %type <op> lbinary_op
177 %type <num> partial_specifier
178 %type <variant> rterm
179 %type <variant> rterm_array
180 %type <variant> rterm_scope
181 %type <variant> lterm
182 %type <variant> object
183 %type <variant> apply
184 %type <text> target_type_specifier
192 %left T_EQUAL T_NOT_EQUAL
193 %left T_LESS_THAN T_LESS_THAN_OR_EQUAL T_GREATER_THAN T_GREATER_THAN_OR_EQUAL
194 %left T_SHIFT_LEFT T_SHIFT_RIGHT
196 %left T_MULTIPLY T_DIVIDE_OP
202 int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
204 void yyerror(YYLTYPE *locp, ConfigCompiler *, const char *err)
206 std::ostringstream message;
207 message << *locp << ": " << err;
208 ConfigCompilerContext::GetInstance()->AddMessage(true, message.str(), *locp);
211 int yyparse(ConfigCompiler *context);
213 static bool m_Abstract;
215 static std::stack<TypeRuleList::Ptr> m_RuleLists;
216 static ConfigType::Ptr m_Type;
218 static Dictionary::Ptr m_ModuleScope;
219 static int m_StatementNum;
222 static bool m_ObjectAssign;
223 static bool m_SeenAssign;
224 static AExpression::Ptr m_Assign;
225 static AExpression::Ptr m_Ignore;
227 void ConfigCompiler::Compile(void)
229 m_ModuleScope = make_shared<Dictionary>();
231 int parentStatementNum = m_StatementNum;
236 } catch (const ConfigError& ex) {
237 const DebugInfo *di = boost::get_error_info<errinfo_debuginfo>(ex);
238 ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo());
239 } catch (const std::exception& ex) {
240 ConfigCompilerContext::GetInstance()->AddMessage(true, DiagnosticInformation(ex));
243 m_StatementNum = parentStatementNum;
246 #define scanner (context->GetScanner())
251 statements: /* empty */
252 | statements statement
255 statement: type | zone | include | include_recursive | library | constant
263 AExpression::Ptr aexpr = *$1;
264 aexpr->Evaluate(m_ModuleScope);
271 zone: T_ZONE rterm sep
273 AExpression::Ptr aexpr = *$2;
276 if (!context->GetZone().IsEmpty())
277 BOOST_THROW_EXCEPTION(std::invalid_argument("Zone name cannot be changed once it's been set."));
279 if (m_StatementNum != 0)
280 BOOST_THROW_EXCEPTION(std::invalid_argument("'zone' directive must be the first statement in a file."));
282 context->SetZone(aexpr->Evaluate(m_ModuleScope));
286 AExpression::Ptr aexpr = *$2;
289 if (!context->GetZone().IsEmpty())
290 BOOST_THROW_EXCEPTION(std::invalid_argument("Zone name cannot be changed once it's been set."));
292 context->SetZone(aexpr->Evaluate(m_ModuleScope));
296 AExpression::Ptr ascope = *$4;
300 ascope->Evaluate(m_ModuleScope);
301 context->SetZone(String());
303 context->SetZone(String());
308 include: T_INCLUDE rterm sep
310 AExpression::Ptr aexpr = *$2;
313 context->HandleInclude(aexpr->Evaluate(m_ModuleScope), false, DebugInfoRange(@1, @2));
315 | T_INCLUDE T_STRING_ANGLE
317 context->HandleInclude($2, true, DebugInfoRange(@1, @2));
322 include_recursive: T_INCLUDE_RECURSIVE rterm
324 AExpression::Ptr aexpr = *$2;
327 context->HandleIncludeRecursive(aexpr->Evaluate(m_ModuleScope), "*.conf", DebugInfoRange(@1, @2));
329 | T_INCLUDE_RECURSIVE rterm ',' rterm
331 AExpression::Ptr aexpr1 = *$2;
334 AExpression::Ptr aexpr2 = *$4;
337 context->HandleIncludeRecursive(aexpr1->Evaluate(m_ModuleScope), aexpr2->Evaluate(m_ModuleScope), DebugInfoRange(@1, @4));
341 library: T_LIBRARY T_STRING sep
343 context->HandleLibrary($2);
348 constant: T_CONST identifier T_SET rterm sep
350 AExpression::Ptr aexpr = *$4;
353 ScriptVariable::Ptr sv = ScriptVariable::Set($2, aexpr->Evaluate(m_ModuleScope));
354 sv->SetConstant(true);
360 identifier: T_IDENTIFIER
367 type: partial_specifier T_TYPE identifier
369 String name = String($3);
372 m_Type = ConfigType::GetByName(name);
376 BOOST_THROW_EXCEPTION(ConfigError("Partial type definition for unknown type '" + name + "'") << errinfo_debuginfo(DebugInfoRange(@1, @3)));
378 m_Type = make_shared<ConfigType>(name, DebugInfoRange(@1, @3));
382 type_inherits_specifier typerulelist sep
384 TypeRuleList::Ptr ruleList = *$6;
385 m_Type->GetRuleList()->AddRules(ruleList);
386 m_Type->GetRuleList()->AddRequires(ruleList);
388 String validator = ruleList->GetValidator();
389 if (!validator.IsEmpty())
390 m_Type->GetRuleList()->SetValidator(validator);
396 partial_specifier: /* Empty */
408 m_RuleLists.push(make_shared<TypeRuleList>());
413 $$ = new Value(m_RuleLists.top());
418 typerules: typerules_inner
419 | typerules_inner sep
421 typerules_inner: /* empty */
423 | typerules_inner sep typerule
426 typerule: T_REQUIRE T_STRING
428 m_RuleLists.top()->AddRequire($2);
431 | T_VALIDATOR T_STRING
433 m_RuleLists.top()->SetValidator($2);
436 | T_ATTRIBUTE type T_STRING
438 TypeRule rule($2, String(), $3, TypeRuleList::Ptr(), DebugInfoRange(@1, @3));
441 m_RuleLists.top()->AddRule(rule);
443 | T_ATTRIBUTE T_TYPE_NAME '(' identifier ')' T_STRING
445 TypeRule rule($2, $4, $6, TypeRuleList::Ptr(), DebugInfoRange(@1, @6));
449 m_RuleLists.top()->AddRule(rule);
451 | T_ATTRIBUTE type T_STRING typerulelist
453 TypeRule rule($2, String(), $3, *$4, DebugInfoRange(@1, @4));
456 m_RuleLists.top()->AddRule(rule);
460 type_inherits_specifier: /* empty */
461 | T_INHERITS identifier
463 m_Type->SetParent($2);
468 type: T_TYPE_DICTIONARY
483 m_ObjectAssign = true;
484 m_SeenAssign = false;
485 m_Assign = make_shared<AExpression>(&AExpression::OpLiteral, false, DebugInfo());
486 m_Ignore = make_shared<AExpression>(&AExpression::OpLiteral, false, DebugInfo());
488 object_declaration identifier rterm rterm_scope
490 m_ObjectAssign = false;
492 Array::Ptr args = make_shared<Array>();
494 args->Add(m_Abstract);
503 AExpression::Ptr exprl = *$5;
507 if (m_SeenAssign && !ObjectRule::IsValidSourceType(type))
508 BOOST_THROW_EXCEPTION(ConfigError("object rule 'assign' cannot be used for type '" + type + "'") << errinfo_debuginfo(DebugInfoRange(@2, @3)));
510 AExpression::Ptr rex = make_shared<AExpression>(&AExpression::OpLogicalNegate, m_Ignore, DebugInfoRange(@2, @5));
511 AExpression::Ptr filter = make_shared<AExpression>(&AExpression::OpLogicalAnd, m_Assign, rex, DebugInfoRange(@2, @5));
515 args->Add(context->GetZone());
517 $$ = new Value(make_shared<AExpression>(&AExpression::OpObject, args, exprl, DebugInfoRange(@2, @5)));
524 object_declaration: T_OBJECT
530 identifier_items: identifier_items_inner
534 | identifier_items_inner ','
540 identifier_items_inner: /* empty */
550 | identifier_items_inner ',' identifier
572 lterm_items: /* empty */
580 | lterm_items_inner sep
585 lterm_items_inner: lterm
591 | lterm_items_inner sep lterm
603 lterm: identifier lbinary_op rterm
605 AExpression::Ptr aindex = make_shared<AExpression>(&AExpression::OpLiteral, $1, @1);
608 $$ = new Value(make_shared<AExpression>($2, aindex, *$3, DebugInfoRange(@1, @3)));
611 | identifier '[' rterm ']' lbinary_op rterm
613 AExpression::Ptr subexpr = make_shared<AExpression>($5, *$3, *$6, DebugInfoRange(@1, @6));
617 Array::Ptr subexprl = make_shared<Array>();
618 subexprl->Add(subexpr);
620 AExpression::Ptr aindex = make_shared<AExpression>(&AExpression::OpLiteral, $1, @1);
623 AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @6));
624 $$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, aindex, expr, DebugInfoRange(@1, @6)));
626 | identifier '.' T_IDENTIFIER lbinary_op rterm
628 AExpression::Ptr aindex = make_shared<AExpression>(&AExpression::OpLiteral, $3, @3);
629 AExpression::Ptr subexpr = make_shared<AExpression>($4, aindex, *$5, DebugInfoRange(@1, @5));
633 Array::Ptr subexprl = make_shared<Array>();
634 subexprl->Add(subexpr);
636 AExpression::Ptr aindexl = make_shared<AExpression>(&AExpression::OpLiteral, $1, @1);
639 AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @5));
640 $$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, aindexl, expr, DebugInfoRange(@1, @5)));
644 AExpression::Ptr avar = make_shared<AExpression>(&AExpression::OpVariable, "type", DebugInfoRange(@1, @2));
645 $$ = new Value(make_shared<AExpression>(&AExpression::OpImport, avar, *$2, DebugInfoRange(@1, @2)));
648 | T_ASSIGN T_WHERE rterm
650 if (!(m_Apply || m_ObjectAssign))
651 BOOST_THROW_EXCEPTION(ConfigError("'assign' keyword not valid in this context."));
655 m_Assign = make_shared<AExpression>(&AExpression::OpLogicalOr, m_Assign, *$3, DebugInfoRange(@1, @3));
658 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, Empty, DebugInfoRange(@1, @3)));
660 | T_IGNORE T_WHERE rterm
662 if (!(m_Apply || m_ObjectAssign))
663 BOOST_THROW_EXCEPTION(ConfigError("'ignore' keyword not valid in this context."));
665 m_Ignore = make_shared<AExpression>(&AExpression::OpLogicalOr, m_Ignore, *$3, DebugInfoRange(@1, @3));
669 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, Empty, DebugInfoRange(@1, @3)));
673 AExpression::Ptr aname = make_shared<AExpression>(&AExpression::OpLiteral, "__result", @1);
674 $$ = new Value(make_shared<AExpression>(&AExpression::OpSet, aname, *$2, DebugInfoRange(@1, @2)));
692 rterm_items: /* empty */
700 | rterm_items_inner arraysep
706 rterm_items_inner: rterm
712 | rterm_items_inner arraysep rterm
720 rterm_array: '[' newlines rterm_items newlines ']'
722 $$ = new Value(make_shared<AExpression>(&AExpression::OpArray, Array::Ptr($3), DebugInfoRange(@1, @5)));
724 | '[' newlines rterm_items ']'
726 $$ = new Value(make_shared<AExpression>(&AExpression::OpArray, Array::Ptr($3), DebugInfoRange(@1, @4)));
728 | '[' rterm_items newlines ']'
730 $$ = new Value(make_shared<AExpression>(&AExpression::OpArray, Array::Ptr($2), DebugInfoRange(@1, @4)));
732 | '[' rterm_items ']'
734 $$ = new Value(make_shared<AExpression>(&AExpression::OpArray, Array::Ptr($2), DebugInfoRange(@1, @3)));
738 rterm_scope: '{' newlines lterm_items newlines '}'
740 $$ = new Value(make_shared<AExpression>(&AExpression::OpDict, Array::Ptr($3), DebugInfoRange(@1, @5)));
742 | '{' newlines lterm_items '}'
744 $$ = new Value(make_shared<AExpression>(&AExpression::OpDict, Array::Ptr($3), DebugInfoRange(@1, @4)));
746 | '{' lterm_items newlines '}'
748 $$ = new Value(make_shared<AExpression>(&AExpression::OpDict, Array::Ptr($2), DebugInfoRange(@1, @4)));
750 | '{' lterm_items '}'
752 $$ = new Value(make_shared<AExpression>(&AExpression::OpDict, Array::Ptr($2), DebugInfoRange(@1, @3)));
758 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, $1, @1));
763 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, $1, @1));
767 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, Empty, @1));
769 | rterm '.' T_IDENTIFIER
771 $$ = new Value(make_shared<AExpression>(&AExpression::OpIndexer, *$1, make_shared<AExpression>(&AExpression::OpLiteral, $3, @3), DebugInfoRange(@1, @3)));
775 | rterm '(' rterm_items ')'
777 Array::Ptr arguments = Array::Ptr($3);
778 $$ = new Value(make_shared<AExpression>(&AExpression::OpFunctionCall, *$1, make_shared<AExpression>(&AExpression::OpLiteral, arguments, @3), DebugInfoRange(@1, @4)));
783 $$ = new Value(make_shared<AExpression>(&AExpression::OpVariable, $1, @1));
788 $$ = new Value(make_shared<AExpression>(&AExpression::OpLogicalNegate, *$2, DebugInfoRange(@1, @2)));
793 $$ = new Value(make_shared<AExpression>(&AExpression::OpNegate, *$2, DebugInfoRange(@1, @2)));
796 | rterm '[' rterm ']'
798 $$ = new Value(make_shared<AExpression>(&AExpression::OpIndexer, *$1, *$3, DebugInfoRange(@1, @4)));
819 | rterm T_LOGICAL_OR rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
820 | rterm T_LOGICAL_AND rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
821 | rterm T_BINARY_OR rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
822 | rterm T_BINARY_AND rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
823 | rterm T_IN rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
824 | rterm T_NOT_IN rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
825 | rterm T_EQUAL rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
826 | rterm T_NOT_EQUAL rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
827 | rterm T_LESS_THAN rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
828 | rterm T_LESS_THAN_OR_EQUAL rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
829 | rterm T_GREATER_THAN rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
830 | rterm T_GREATER_THAN_OR_EQUAL rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
831 | rterm T_SHIFT_LEFT rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
832 | rterm T_SHIFT_RIGHT rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
833 | rterm T_PLUS rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
834 | rterm T_MINUS rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
835 | rterm T_MULTIPLY rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
836 | rterm T_DIVIDE_OP rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
837 | T_FUNCTION identifier '(' identifier_items ')' rterm_scope
839 Array::Ptr arr = make_shared<Array>();
844 AExpression::Ptr aexpr = *$6;
849 $$ = new Value(make_shared<AExpression>(&AExpression::OpFunction, arr, Array::Ptr($4), DebugInfoRange(@1, @6)));
851 | T_FUNCTION '(' identifier_items ')' rterm_scope
853 Array::Ptr arr = make_shared<Array>();
857 AExpression::Ptr aexpr = *$5;
862 $$ = new Value(make_shared<AExpression>(&AExpression::OpFunction, arr, Array::Ptr($3), DebugInfoRange(@1, @5)));
864 | T_FOR '(' identifier T_IN rterm ')' rterm_scope
866 Array::Ptr arr = make_shared<Array>();
871 AExpression::Ptr aexpr = *$5;
875 AExpression::Ptr ascope = *$7;
878 $$ = new Value(make_shared<AExpression>(&AExpression::OpFor, arr, ascope, DebugInfoRange(@1, @7)));
882 target_type_specifier: /* empty */
895 m_SeenAssign = false;
896 m_Assign = make_shared<AExpression>(&AExpression::OpLiteral, false, DebugInfo());
897 m_Ignore = make_shared<AExpression>(&AExpression::OpLiteral, false, DebugInfo());
899 T_APPLY identifier rterm target_type_specifier rterm
905 AExpression::Ptr aname = *$4;
910 if (!ApplyRule::IsValidSourceType(type))
911 BOOST_THROW_EXCEPTION(ConfigError("'apply' cannot be used with type '" + type + "'") << errinfo_debuginfo(DebugInfoRange(@2, @3)));
913 if (!ApplyRule::IsValidTargetType(type, target)) {
915 std::vector<String> types = ApplyRule::GetTargetTypes(type);
918 for (std::vector<String>::size_type i = 0; i < types.size(); i++) {
919 if (typeNames != "") {
920 if (i == types.size() - 1)
926 typeNames += "'" + types[i] + "'";
929 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)));
931 BOOST_THROW_EXCEPTION(ConfigError("'apply' target type '" + target + "' is invalid") << errinfo_debuginfo(DebugInfoRange(@2, @5)));
934 AExpression::Ptr exprl = *$6;
941 BOOST_THROW_EXCEPTION(ConfigError("'apply' is missing 'assign'") << errinfo_debuginfo(DebugInfoRange(@2, @3)));
943 AExpression::Ptr rex = make_shared<AExpression>(&AExpression::OpLogicalNegate, m_Ignore, DebugInfoRange(@2, @5));
944 AExpression::Ptr filter = make_shared<AExpression>(&AExpression::OpLogicalAnd, m_Assign, rex, DebugInfoRange(@2, @5));
946 Array::Ptr args = make_shared<Array>();
952 $$ = new Value(make_shared<AExpression>(&AExpression::OpApply, args, exprl, DebugInfoRange(@2, @5)));
963 /* required separator */
971 arraysep: ',' newlines