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 "i2-config.h"
24 #include "config/configitembuilder.h"
25 #include "config/configtype.h"
26 #include "config/configcompiler.h"
27 #include "config/configcompilercontext.h"
28 #include "config/configerror.h"
29 #include "config/typerule.h"
30 #include "config/typerulelist.h"
31 #include "config/aexpression.h"
32 #include "config/applyrule.h"
33 #include "config/objectrule.h"
34 #include "config/aexpression.h"
35 #include "base/value.h"
36 #include "base/utility.h"
37 #include "base/array.h"
38 #include "base/scriptvariable.h"
39 #include "base/exception.h"
40 #include "base/dynamictype.h"
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_LAMBDA "lambda (T_LAMBDA)"
164 %token T_RETURN "return (T_RETURN)"
165 %token T_ZONE "zone (T_ZONE)"
166 %token T_FOR "for (T_FOR)"
168 %type <text> identifier
169 %type <array> rterm_items
170 %type <array> rterm_items_inner
171 %type <array> identifier_items
172 %type <array> identifier_items_inner
173 %type <array> lterm_items
174 %type <array> lterm_items_inner
175 %type <variant> typerulelist
176 %type <op> lbinary_op
178 %type <num> partial_specifier
179 %type <variant> rterm
180 %type <variant> rterm_array
181 %type <variant> rterm_scope
182 %type <variant> lterm
183 %type <variant> object
184 %type <variant> apply
185 %type <text> target_type_specifier
193 %left T_EQUAL T_NOT_EQUAL
194 %left T_LESS_THAN T_LESS_THAN_OR_EQUAL T_GREATER_THAN T_GREATER_THAN_OR_EQUAL
195 %left T_SHIFT_LEFT T_SHIFT_RIGHT
197 %left T_MULTIPLY T_DIVIDE_OP
203 int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
205 void yyerror(YYLTYPE *locp, ConfigCompiler *, const char *err)
207 std::ostringstream message;
208 message << *locp << ": " << err;
209 ConfigCompilerContext::GetInstance()->AddMessage(true, message.str(), *locp);
212 int yyparse(ConfigCompiler *context);
214 static bool m_Abstract;
216 static std::stack<TypeRuleList::Ptr> m_RuleLists;
217 static ConfigType::Ptr m_Type;
219 static Dictionary::Ptr m_ModuleScope;
220 static String m_Zone;
221 static int m_StatementNum;
224 static bool m_ObjectAssign;
225 static bool m_SeenAssign;
226 static AExpression::Ptr m_Assign;
227 static AExpression::Ptr m_Ignore;
229 void ConfigCompiler::Compile(void)
231 m_ModuleScope = make_shared<Dictionary>();
233 String parentZone = m_Zone;
234 int parentStatementNum = m_StatementNum;
239 } catch (const ConfigError& ex) {
240 const DebugInfo *di = boost::get_error_info<errinfo_debuginfo>(ex);
241 ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo());
242 } catch (const std::exception& ex) {
243 ConfigCompilerContext::GetInstance()->AddMessage(true, DiagnosticInformation(ex));
247 m_StatementNum = parentStatementNum;
250 #define scanner (context->GetScanner())
255 statements: /* empty */
256 | statements statement
259 statement: type | zone | include | include_recursive | library | constant
267 AExpression::Ptr aexpr = *$1;
268 aexpr->Evaluate(m_ModuleScope);
275 zone: T_ZONE rterm sep
277 AExpression::Ptr aexpr = *$2;
280 if (!m_Zone.IsEmpty())
281 BOOST_THROW_EXCEPTION(std::invalid_argument("Zone name cannot be changed once it's been set."));
283 if (m_StatementNum != 0)
284 BOOST_THROW_EXCEPTION(std::invalid_argument("'zone' directive must be the first statement in a file."));
286 m_Zone = aexpr->Evaluate(m_ModuleScope);
290 AExpression::Ptr aexpr = *$2;
293 if (!m_Zone.IsEmpty())
294 BOOST_THROW_EXCEPTION(std::invalid_argument("Zone name cannot be changed once it's been set."));
296 m_Zone = aexpr->Evaluate(m_ModuleScope);
300 AExpression::Ptr ascope = *$4;
304 ascope->Evaluate(m_ModuleScope);
312 include: T_INCLUDE rterm sep
314 AExpression::Ptr aexpr = *$2;
317 context->HandleInclude(aexpr->Evaluate(m_ModuleScope), false, DebugInfoRange(@1, @2));
319 | T_INCLUDE T_STRING_ANGLE
321 context->HandleInclude($2, true, DebugInfoRange(@1, @2));
326 include_recursive: T_INCLUDE_RECURSIVE rterm
328 AExpression::Ptr aexpr = *$2;
331 context->HandleIncludeRecursive(aexpr->Evaluate(m_ModuleScope), "*.conf", DebugInfoRange(@1, @2));
333 | T_INCLUDE_RECURSIVE rterm ',' rterm
335 AExpression::Ptr aexpr1 = *$2;
338 AExpression::Ptr aexpr2 = *$4;
341 context->HandleIncludeRecursive(aexpr1->Evaluate(m_ModuleScope), aexpr2->Evaluate(m_ModuleScope), DebugInfoRange(@1, @4));
345 library: T_LIBRARY T_STRING sep
347 context->HandleLibrary($2);
352 constant: T_CONST identifier T_SET rterm sep
354 AExpression::Ptr aexpr = *$4;
357 ScriptVariable::Ptr sv = ScriptVariable::Set($2, aexpr->Evaluate(m_ModuleScope));
358 sv->SetConstant(true);
364 identifier: T_IDENTIFIER
371 type: partial_specifier T_TYPE identifier
373 String name = String($3);
376 m_Type = ConfigType::GetByName(name);
380 BOOST_THROW_EXCEPTION(ConfigError("Partial type definition for unknown type '" + name + "'") << errinfo_debuginfo(DebugInfoRange(@1, @3)));
382 m_Type = make_shared<ConfigType>(name, DebugInfoRange(@1, @3));
386 type_inherits_specifier typerulelist sep
388 TypeRuleList::Ptr ruleList = *$6;
389 m_Type->GetRuleList()->AddRules(ruleList);
390 m_Type->GetRuleList()->AddRequires(ruleList);
392 String validator = ruleList->GetValidator();
393 if (!validator.IsEmpty())
394 m_Type->GetRuleList()->SetValidator(validator);
400 partial_specifier: /* Empty */
412 m_RuleLists.push(make_shared<TypeRuleList>());
417 $$ = new Value(m_RuleLists.top());
422 typerules: typerules_inner
423 | typerules_inner sep
425 typerules_inner: /* empty */
427 | typerules_inner sep typerule
430 typerule: T_REQUIRE T_STRING
432 m_RuleLists.top()->AddRequire($2);
435 | T_VALIDATOR T_STRING
437 m_RuleLists.top()->SetValidator($2);
440 | T_ATTRIBUTE type T_STRING
442 TypeRule rule($2, String(), $3, TypeRuleList::Ptr(), DebugInfoRange(@1, @3));
445 m_RuleLists.top()->AddRule(rule);
447 | T_ATTRIBUTE T_TYPE_NAME '(' identifier ')' T_STRING
449 TypeRule rule($2, $4, $6, TypeRuleList::Ptr(), DebugInfoRange(@1, @6));
453 m_RuleLists.top()->AddRule(rule);
455 | T_ATTRIBUTE type T_STRING typerulelist
457 TypeRule rule($2, String(), $3, *$4, DebugInfoRange(@1, @4));
460 m_RuleLists.top()->AddRule(rule);
464 type_inherits_specifier: /* empty */
465 | T_INHERITS identifier
467 m_Type->SetParent($2);
472 type: T_TYPE_DICTIONARY
487 m_ObjectAssign = true;
488 m_SeenAssign = false;
489 m_Assign = make_shared<AExpression>(&AExpression::OpLiteral, false, DebugInfo());
490 m_Ignore = make_shared<AExpression>(&AExpression::OpLiteral, false, DebugInfo());
492 object_declaration identifier rterm rterm_scope
494 m_ObjectAssign = false;
496 Array::Ptr args = make_shared<Array>();
498 args->Add(m_Abstract);
507 AExpression::Ptr exprl = *$5;
511 if (m_SeenAssign && !ObjectRule::IsValidSourceType(type))
512 BOOST_THROW_EXCEPTION(ConfigError("object rule 'assign' cannot be used for type '" + type + "'") << errinfo_debuginfo(DebugInfoRange(@2, @3)));
514 AExpression::Ptr rex = make_shared<AExpression>(&AExpression::OpLogicalNegate, m_Ignore, DebugInfoRange(@2, @5));
515 AExpression::Ptr filter = make_shared<AExpression>(&AExpression::OpLogicalAnd, m_Assign, rex, DebugInfoRange(@2, @5));
521 $$ = new Value(make_shared<AExpression>(&AExpression::OpObject, args, exprl, DebugInfoRange(@2, @5)));
528 object_declaration: T_OBJECT
534 identifier_items: identifier_items_inner
538 | identifier_items_inner ','
544 identifier_items_inner: /* empty */
554 | identifier_items_inner ',' identifier
576 lterm_items: /* empty */
584 | lterm_items_inner sep
589 lterm_items_inner: lterm
595 | lterm_items_inner sep lterm
607 lterm: identifier lbinary_op rterm
609 AExpression::Ptr aindex = make_shared<AExpression>(&AExpression::OpLiteral, $1, @1);
612 $$ = new Value(make_shared<AExpression>($2, aindex, *$3, DebugInfoRange(@1, @3)));
615 | identifier '[' rterm ']' lbinary_op rterm
617 AExpression::Ptr subexpr = make_shared<AExpression>($5, *$3, *$6, DebugInfoRange(@1, @6));
621 Array::Ptr subexprl = make_shared<Array>();
622 subexprl->Add(subexpr);
624 AExpression::Ptr aindex = make_shared<AExpression>(&AExpression::OpLiteral, $1, @1);
627 AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @6));
628 $$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, aindex, expr, DebugInfoRange(@1, @6)));
630 | identifier '.' T_IDENTIFIER lbinary_op rterm
632 AExpression::Ptr aindex = make_shared<AExpression>(&AExpression::OpLiteral, $3, @3);
633 AExpression::Ptr subexpr = make_shared<AExpression>($4, aindex, *$5, DebugInfoRange(@1, @5));
637 Array::Ptr subexprl = make_shared<Array>();
638 subexprl->Add(subexpr);
640 AExpression::Ptr aindexl = make_shared<AExpression>(&AExpression::OpLiteral, $1, @1);
643 AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @5));
644 $$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, aindexl, expr, DebugInfoRange(@1, @5)));
648 AExpression::Ptr avar = make_shared<AExpression>(&AExpression::OpVariable, "type", DebugInfoRange(@1, @2));
649 $$ = new Value(make_shared<AExpression>(&AExpression::OpImport, avar, *$2, DebugInfoRange(@1, @2)));
652 | T_ASSIGN T_WHERE rterm
654 if (!(m_Apply || m_ObjectAssign))
655 BOOST_THROW_EXCEPTION(ConfigError("'assign' keyword not valid in this context."));
659 m_Assign = make_shared<AExpression>(&AExpression::OpLogicalOr, m_Assign, *$3, DebugInfoRange(@1, @3));
662 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, Empty, DebugInfoRange(@1, @3)));
664 | T_IGNORE T_WHERE rterm
666 if (!(m_Apply || m_ObjectAssign))
667 BOOST_THROW_EXCEPTION(ConfigError("'ignore' keyword not valid in this context."));
669 m_Ignore = make_shared<AExpression>(&AExpression::OpLogicalOr, m_Ignore, *$3, DebugInfoRange(@1, @3));
673 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, Empty, DebugInfoRange(@1, @3)));
677 AExpression::Ptr aname = make_shared<AExpression>(&AExpression::OpLiteral, "__result", @1);
678 $$ = new Value(make_shared<AExpression>(&AExpression::OpSet, aname, *$2, DebugInfoRange(@1, @2)));
696 rterm_items: /* empty */
704 | rterm_items_inner arraysep
710 rterm_items_inner: rterm
716 | rterm_items_inner arraysep rterm
724 rterm_array: '[' newlines rterm_items newlines ']'
726 $$ = new Value(make_shared<AExpression>(&AExpression::OpArray, Array::Ptr($3), DebugInfoRange(@1, @5)));
728 | '[' newlines rterm_items ']'
730 $$ = new Value(make_shared<AExpression>(&AExpression::OpArray, Array::Ptr($3), DebugInfoRange(@1, @4)));
732 | '[' rterm_items newlines ']'
734 $$ = new Value(make_shared<AExpression>(&AExpression::OpArray, Array::Ptr($2), DebugInfoRange(@1, @4)));
736 | '[' rterm_items ']'
738 $$ = new Value(make_shared<AExpression>(&AExpression::OpArray, Array::Ptr($2), DebugInfoRange(@1, @3)));
742 rterm_scope: '{' newlines lterm_items newlines '}'
744 $$ = new Value(make_shared<AExpression>(&AExpression::OpDict, Array::Ptr($3), DebugInfoRange(@1, @5)));
746 | '{' newlines lterm_items '}'
748 $$ = new Value(make_shared<AExpression>(&AExpression::OpDict, Array::Ptr($3), DebugInfoRange(@1, @4)));
750 | '{' lterm_items newlines '}'
752 $$ = new Value(make_shared<AExpression>(&AExpression::OpDict, Array::Ptr($2), DebugInfoRange(@1, @4)));
754 | '{' lterm_items '}'
756 $$ = new Value(make_shared<AExpression>(&AExpression::OpDict, Array::Ptr($2), DebugInfoRange(@1, @3)));
762 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, $1, @1));
767 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, $1, @1));
771 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, Empty, @1));
773 | rterm '.' T_IDENTIFIER
775 $$ = new Value(make_shared<AExpression>(&AExpression::OpIndexer, *$1, make_shared<AExpression>(&AExpression::OpLiteral, $3, @3), DebugInfoRange(@1, @3)));
779 | rterm '(' rterm_items ')'
781 Array::Ptr arguments = Array::Ptr($3);
782 $$ = new Value(make_shared<AExpression>(&AExpression::OpFunctionCall, *$1, make_shared<AExpression>(&AExpression::OpLiteral, arguments, @3), DebugInfoRange(@1, @4)));
787 $$ = new Value(make_shared<AExpression>(&AExpression::OpVariable, $1, @1));
792 $$ = new Value(make_shared<AExpression>(&AExpression::OpLogicalNegate, *$2, DebugInfoRange(@1, @2)));
797 $$ = new Value(make_shared<AExpression>(&AExpression::OpNegate, *$2, DebugInfoRange(@1, @2)));
800 | rterm '[' rterm ']'
802 $$ = new Value(make_shared<AExpression>(&AExpression::OpIndexer, *$1, *$3, DebugInfoRange(@1, @4)));
823 | rterm T_LOGICAL_OR rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
824 | rterm T_LOGICAL_AND rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
825 | rterm T_BINARY_OR rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
826 | rterm T_BINARY_AND rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
827 | rterm T_IN rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
828 | rterm T_NOT_IN rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
829 | rterm T_EQUAL rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
830 | rterm T_NOT_EQUAL rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
831 | rterm T_LESS_THAN rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
832 | rterm T_LESS_THAN_OR_EQUAL rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
833 | rterm T_GREATER_THAN rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
834 | rterm T_GREATER_THAN_OR_EQUAL rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
835 | rterm T_SHIFT_LEFT rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
836 | rterm T_SHIFT_RIGHT rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
837 | rterm T_PLUS rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
838 | rterm T_MINUS rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
839 | rterm T_MULTIPLY rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
840 | rterm T_DIVIDE_OP rterm { MakeRBinaryOp(&$$, $2, $1, $3, @1, @3); }
841 | T_FUNCTION identifier '(' identifier_items ')' rterm_scope
843 Array::Ptr arr = make_shared<Array>();
848 AExpression::Ptr aexpr = *$6;
853 $$ = new Value(make_shared<AExpression>(&AExpression::OpFunction, arr, Array::Ptr($4), DebugInfoRange(@1, @6)));
855 | T_FUNCTION '(' identifier_items ')' rterm_scope
857 Array::Ptr arr = make_shared<Array>();
861 AExpression::Ptr aexpr = *$5;
866 $$ = new Value(make_shared<AExpression>(&AExpression::OpFunction, arr, Array::Ptr($3), DebugInfoRange(@1, @5)));
868 | T_LAMBDA identifier_items ':' rterm
870 Array::Ptr arr = make_shared<Array>();
874 Array::Ptr arrex = make_shared<Array>();
875 arrex->Add(make_shared<AExpression>(&AExpression::OpSet, make_shared<AExpression>(&AExpression::OpLiteral, "__result", @4), *$4, @4));
877 AExpression::Ptr aexpr = make_shared<AExpression>(&AExpression::OpDict, arrex, true, @4);
881 $$ = new Value(make_shared<AExpression>(&AExpression::OpFunction, arr, Array::Ptr($2), DebugInfoRange(@1, @4)));
883 | T_FOR '(' identifier T_IN rterm ')' rterm_scope
885 Array::Ptr arr = make_shared<Array>();
890 AExpression::Ptr aexpr = *$5;
894 AExpression::Ptr ascope = *$7;
897 $$ = new Value(make_shared<AExpression>(&AExpression::OpFor, arr, ascope, DebugInfoRange(@1, @7)));
901 target_type_specifier: /* empty */
914 m_SeenAssign = false;
915 m_Assign = make_shared<AExpression>(&AExpression::OpLiteral, false, DebugInfo());
916 m_Ignore = make_shared<AExpression>(&AExpression::OpLiteral, false, DebugInfo());
918 T_APPLY identifier rterm target_type_specifier rterm
924 AExpression::Ptr aname = *$4;
929 if (!ApplyRule::IsValidSourceType(type))
930 BOOST_THROW_EXCEPTION(ConfigError("'apply' cannot be used with type '" + type + "'") << errinfo_debuginfo(DebugInfoRange(@2, @3)));
932 if (!ApplyRule::IsValidTargetType(type, target)) {
934 std::vector<String> types = ApplyRule::GetTargetTypes(type);
937 for (std::vector<String>::size_type i = 0; i < types.size(); i++) {
938 if (typeNames != "") {
939 if (i == types.size() - 1)
945 typeNames += "'" + types[i] + "'";
948 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)));
950 BOOST_THROW_EXCEPTION(ConfigError("'apply' target type '" + target + "' is invalid") << errinfo_debuginfo(DebugInfoRange(@2, @5)));
953 AExpression::Ptr exprl = *$6;
960 BOOST_THROW_EXCEPTION(ConfigError("'apply' is missing 'assign'") << errinfo_debuginfo(DebugInfoRange(@2, @3)));
962 AExpression::Ptr rex = make_shared<AExpression>(&AExpression::OpLogicalNegate, m_Ignore, DebugInfoRange(@2, @5));
963 AExpression::Ptr filter = make_shared<AExpression>(&AExpression::OpLogicalAnd, m_Assign, rex, DebugInfoRange(@2, @5));
965 Array::Ptr args = make_shared<Array>();
971 $$ = new Value(make_shared<AExpression>(&AExpression::OpApply, args, exprl, DebugInfoRange(@2, @5)));
982 /* required separator */
990 arraysep: ',' newlines