]> granicus.if.org Git - icinga2/blob - lib/config/config_parser.yy
Implement the "." operator.
[icinga2] / lib / config / config_parser.yy
1 %{
2  #define YYDEBUG 1
3  
4 /******************************************************************************
5  * Icinga 2                                                                   *
6  * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)    *
7  *                                                                            *
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.                     *
12  *                                                                            *
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.                               *
17  *                                                                            *
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  ******************************************************************************/
22
23 #include "i2-config.h"
24 #include "config/configitembuilder.h"
25 #include "config/configcompiler.h"
26 #include "config/configcompilercontext.h"
27 #include "config/configerror.h"
28 #include "config/typerule.h"
29 #include "config/typerulelist.h"
30 #include "config/aexpression.h"
31 #include "config/applyrule.h"
32 #include "base/value.h"
33 #include "base/utility.h"
34 #include "base/array.h"
35 #include "base/scriptvariable.h"
36 #include "base/exception.h"
37 #include "base/dynamictype.h"
38 #include <sstream>
39 #include <stack>
40 #include <boost/foreach.hpp>
41
42 #define YYLTYPE icinga::DebugInfo
43 #define YYERROR_VERBOSE
44
45 #define YYLLOC_DEFAULT(Current, Rhs, N)                                 \
46 do {                                                                    \
47         if (N) {                                                        \
48                 (Current).Path = YYRHSLOC(Rhs, 1).Path;                 \
49                 (Current).FirstLine = YYRHSLOC(Rhs, 1).FirstLine;       \
50                 (Current).FirstColumn = YYRHSLOC(Rhs, 1).FirstColumn;   \
51                 (Current).LastLine = YYRHSLOC(Rhs, N).LastLine;         \
52                 (Current).LastColumn = YYRHSLOC(Rhs, N).LastColumn;     \
53         } else {                                                        \
54                 (Current).Path = YYRHSLOC(Rhs, 0).Path;                 \
55                 (Current).FirstLine = (Current).LastLine =              \
56                 YYRHSLOC(Rhs, 0).LastLine;                              \
57                 (Current).FirstColumn = (Current).LastColumn =          \
58                 YYRHSLOC(Rhs, 0).LastColumn;                            \
59         }                                                               \
60 } while (0)
61
62 #define YY_LOCATION_PRINT(file, loc)                    \
63 do {                                                    \
64        std::ostringstream msgbuf;                       \
65        msgbuf << loc;                                   \
66        std::string str = msgbuf.str();                  \
67        fputs(str.c_str(), file);                        \
68 } while (0)
69
70 using namespace icinga;
71
72 %}
73
74 %pure-parser
75
76 %locations
77 %defines
78 %error-verbose
79
80 %parse-param { ConfigCompiler *context }
81 %lex-param { void *scanner }
82
83 %union {
84         char *text;
85         double num;
86         icinga::Value *variant;
87         icinga::AExpression::OpCallback op;
88         icinga::TypeSpecifier type;
89         std::vector<String> *slist;
90         Array *array;
91 }
92
93 %token <text> T_STRING
94 %token <text> T_STRING_ANGLE
95 %token <num> T_NUMBER
96 %token T_NULL
97 %token <text> T_IDENTIFIER
98
99 %token <op> T_SET "= (T_SET)"
100 %token <op> T_SET_PLUS "+= (T_SET_PLUS)"
101 %token <op> T_SET_MINUS "-= (T_SET_MINUS)"
102 %token <op> T_SET_MULTIPLY "*= (T_SET_MULTIPLY)"
103 %token <op> T_SET_DIVIDE "/= (T_SET_DIVIDE)"
104
105 %token <op> T_SHIFT_LEFT "<< (T_SHIFT_LEFT)"
106 %token <op> T_SHIFT_RIGHT ">> (T_SHIFT_RIGHT)"
107 %token <op> T_EQUAL "== (T_EQUAL)"
108 %token <op> T_NOT_EQUAL "!= (T_NOT_EQUAL)"
109 %token <op> T_IN "in (T_IN)"
110 %token <op> T_NOT_IN "!in (T_NOT_IN)"
111 %token <op> T_LOGICAL_AND "&& (T_LOGICAL_AND)"
112 %token <op> T_LOGICAL_OR "|| (T_LOGICAL_OR)"
113 %token <op> T_LESS_THAN_OR_EQUAL "<= (T_LESS_THAN_OR_EQUAL)"
114 %token <op> T_GREATER_THAN_OR_EQUAL ">= (T_GREATER_THAN_OR_EQUAL)"
115 %token <op> T_PLUS "+ (T_PLUS)"
116 %token <op> T_MINUS "- (T_MINUS)"
117 %token <op> T_MULTIPLY "* (T_MULTIPLY)"
118 %token <op> T_DIVIDE_OP "/ (T_DIVIDE_OP)"
119 %token <op> T_BINARY_AND "& (T_BINARY_AND)"
120 %token <op> T_BINARY_OR "| (T_BINARY_OR)"
121 %token <op> T_LESS_THAN "< (T_LESS_THAN)"
122 %token <op> T_GREATER_THAN "> (T_GREATER_THAN)"
123
124 %token T_VAR "var (T_VAR)"
125 %token T_CONST "const (T_CONST)"
126 %token <type> T_TYPE_DICTIONARY "dictionary (T_TYPE_DICTIONARY)"
127 %token <type> T_TYPE_ARRAY "array (T_TYPE_ARRAY)"
128 %token <type> T_TYPE_NUMBER "number (T_TYPE_NUMBER)"
129 %token <type> T_TYPE_STRING "string (T_TYPE_STRING)"
130 %token <type> T_TYPE_SCALAR "scalar (T_TYPE_SCALAR)"
131 %token <type> T_TYPE_ANY "any (T_TYPE_ANY)"
132 %token <type> T_TYPE_NAME "name (T_TYPE_NAME)"
133 %token T_VALIDATOR "%validator (T_VALIDATOR)"
134 %token T_REQUIRE "%require (T_REQUIRE)"
135 %token T_ATTRIBUTE "%attribute (T_ATTRIBUTE)"
136 %token T_TYPE "type (T_TYPE)"
137 %token T_OBJECT "object (T_OBJECT)"
138 %token T_TEMPLATE "template (T_TEMPLATE)"
139 %token T_INCLUDE "include (T_INCLUDE)"
140 %token T_INCLUDE_RECURSIVE "include_recursive (T_INCLUDE_RECURSIVE)"
141 %token T_LIBRARY "library (T_LIBRARY)"
142 %token T_INHERITS "inherits (T_INHERITS)"
143 %token T_PARTIAL "partial (T_PARTIAL)"
144 %token T_APPLY "apply (T_APPLY)"
145 %token T_TO "to (T_TO)"
146 %token T_WHERE "where (T_WHERE)"
147 %token T_IMPORT "import (T_IMPORT)"
148 %type <text> identifier
149 %type <array> rterm_items
150 %type <array> rterm_items_inner
151 %type <array> lterm_items
152 %type <array> lterm_items_inner
153 %type <variant> typerulelist
154 %type <op> lbinary_op
155 %type <op> rbinary_op
156 %type <type> type
157 %type <num> partial_specifier
158 %type <variant> rterm
159 %type <variant> rterm_scope
160 %type <variant> lterm
161 %type <num> variable_decl
162 %left T_LOGICAL_OR
163 %left T_LOGICAL_AND
164 %left T_IN
165 %left T_NOT_IN
166 %nonassoc T_EQUAL
167 %nonassoc T_NOT_EQUAL
168 %left T_PLUS T_MINUS
169 %left T_MULTIPLY T_DIVIDE_OP
170 %left T_BINARY_AND
171 %left T_BINARY_OR
172 %left '.'
173 %right '~'
174 %right '!'
175 %{
176
177 int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
178
179 void yyerror(YYLTYPE *locp, ConfigCompiler *, const char *err)
180 {
181         std::ostringstream message;
182         message << *locp << ": " << err;
183         ConfigCompilerContext::GetInstance()->AddMessage(true, message.str(), *locp);
184 }
185
186 int yyparse(ConfigCompiler *context);
187
188 static bool m_Abstract;
189
190 static std::stack<TypeRuleList::Ptr> m_RuleLists;
191 static ConfigType::Ptr m_Type;
192
193 static Dictionary::Ptr m_ModuleScope;
194
195 void ConfigCompiler::Compile(void)
196 {
197         m_ModuleScope = make_shared<Dictionary>();
198
199         try {
200                 yyparse(this);
201         } catch (const ConfigError& ex) {
202                 const DebugInfo *di = boost::get_error_info<errinfo_debuginfo>(ex);
203                 ConfigCompilerContext::GetInstance()->AddMessage(true, ex.what(), di ? *di : DebugInfo());
204         } catch (const std::exception& ex) {
205                 ConfigCompilerContext::GetInstance()->AddMessage(true, DiagnosticInformation(ex));
206         }
207 }
208
209 #define scanner (context->GetScanner())
210
211 %}
212
213 %%
214 statements: /* empty */
215         | statements statement
216         ;
217
218 statement: object | type | include | include_recursive | library | variable | apply
219         { }
220         | lterm
221         {
222                 AExpression::Ptr aexpr = *$1;
223                 aexpr->Evaluate(m_ModuleScope);
224                 delete $1;
225         }
226         ;
227
228 include: T_INCLUDE rterm
229         {
230                 AExpression::Ptr aexpr = static_cast<AExpression::Ptr>(*$2);
231                 delete $2;
232
233                 context->HandleInclude(aexpr->Evaluate(m_ModuleScope), false, DebugInfoRange(@1, @2));
234         }
235         | T_INCLUDE T_STRING_ANGLE
236         {
237                 context->HandleInclude($2, true, DebugInfoRange(@1, @2));
238                 free($2);
239         }
240         ;
241
242 include_recursive: T_INCLUDE_RECURSIVE rterm
243         {
244                 AExpression::Ptr aexpr = static_cast<AExpression::Ptr>(*$2);
245                 delete $2;
246
247                 context->HandleIncludeRecursive(aexpr->Evaluate(m_ModuleScope), "*.conf", DebugInfoRange(@1, @2));
248         }
249         | T_INCLUDE_RECURSIVE rterm rterm
250         {
251                 AExpression::Ptr aexpr1 = static_cast<AExpression::Ptr>(*$2);
252                 delete $2;
253
254                 AExpression::Ptr aexpr2 = static_cast<AExpression::Ptr>(*$3);
255                 delete $3;
256
257                 context->HandleIncludeRecursive(aexpr1->Evaluate(m_ModuleScope), aexpr2->Evaluate(m_ModuleScope), DebugInfoRange(@1, @3));
258         }
259         ;
260
261 library: T_LIBRARY T_STRING
262         {
263                 context->HandleLibrary($2);
264                 free($2);
265         }
266         ;
267
268 variable: variable_decl identifier T_SET rterm
269         {
270                 AExpression::Ptr aexpr = static_cast<AExpression::Ptr>(*$4);
271                 delete $4;
272
273                 ScriptVariable::Ptr sv = ScriptVariable::Set($2, aexpr->Evaluate(m_ModuleScope));
274                 sv->SetConstant(true);
275
276                 free($2);
277         }
278         ;
279
280 variable_decl: T_VAR
281         {
282                 $$ = true;
283         }
284         | T_CONST
285         {
286                 $$ = false;
287         }
288         ;
289
290 identifier: T_IDENTIFIER
291         | T_STRING
292         {
293                 $$ = $1;
294         }
295         ;
296
297 type: partial_specifier T_TYPE identifier
298         {
299                 String name = String($3);
300                 free($3);
301
302                 m_Type = ConfigType::GetByName(name);
303
304                 if (!m_Type) {
305                         if ($1)
306                                 BOOST_THROW_EXCEPTION(ConfigError("Partial type definition for unknown type '" + name + "'") << errinfo_debuginfo(DebugInfoRange(@1, @3)));
307
308                         m_Type = make_shared<ConfigType>(name, DebugInfoRange(@1, @3));
309                         m_Type->Register();
310                 }
311         }
312         type_inherits_specifier typerulelist
313         {
314                 TypeRuleList::Ptr ruleList = *$6;
315                 m_Type->GetRuleList()->AddRules(ruleList);
316                 m_Type->GetRuleList()->AddRequires(ruleList);
317
318                 String validator = ruleList->GetValidator();
319                 if (!validator.IsEmpty())
320                         m_Type->GetRuleList()->SetValidator(validator);
321
322                 delete $6;
323         }
324         ;
325
326 partial_specifier: /* Empty */
327         {
328                 $$ = 0;
329         }
330         | T_PARTIAL
331         {
332                 $$ = 1;
333         }
334         ;
335
336 typerulelist: '{'
337         {
338                 m_RuleLists.push(make_shared<TypeRuleList>());
339         }
340         typerules
341         '}'
342         {
343                 $$ = new Value(m_RuleLists.top());
344                 m_RuleLists.pop();
345         }
346         ;
347
348 typerules: typerules_inner
349         | typerules_inner ','
350
351 typerules_inner: /* empty */
352         | typerule
353         | typerules_inner ',' typerule
354         ;
355
356 typerule: T_REQUIRE T_STRING
357         {
358                 m_RuleLists.top()->AddRequire($2);
359                 free($2);
360         }
361         | T_VALIDATOR T_STRING
362         {
363                 m_RuleLists.top()->SetValidator($2);
364                 free($2);
365         }
366         | T_ATTRIBUTE type T_STRING
367         {
368                 TypeRule rule($2, String(), $3, TypeRuleList::Ptr(), DebugInfoRange(@1, @3));
369                 free($3);
370
371                 m_RuleLists.top()->AddRule(rule);
372         }
373         | T_ATTRIBUTE T_TYPE_NAME '(' identifier ')' T_STRING
374         {
375                 TypeRule rule($2, $4, $6, TypeRuleList::Ptr(), DebugInfoRange(@1, @6));
376                 free($4);
377                 free($6);
378
379                 m_RuleLists.top()->AddRule(rule);
380         }
381         | T_ATTRIBUTE type T_STRING typerulelist
382         {
383                 TypeRule rule($2, String(), $3, *$4, DebugInfoRange(@1, @4));
384                 free($3);
385                 delete $4;
386                 m_RuleLists.top()->AddRule(rule);
387         }
388         ;
389
390 type_inherits_specifier: /* empty */
391         | T_INHERITS identifier
392         {
393                 m_Type->SetParent($2);
394                 free($2);
395         }
396         ;
397
398 type: T_TYPE_DICTIONARY
399         | T_TYPE_ARRAY
400         | T_TYPE_NUMBER
401         | T_TYPE_STRING
402         | T_TYPE_SCALAR
403         | T_TYPE_ANY
404         | T_TYPE_NAME
405         {
406                 $$ = $1;
407         }
408         ;
409
410 object:
411         {
412                 m_Abstract = false;
413         }
414         object_declaration identifier rterm rterm_scope
415         {
416                 DebugInfo di = DebugInfoRange(@2, @5);
417                 ConfigItemBuilder::Ptr item = make_shared<ConfigItemBuilder>(di);
418
419                 AExpression::Ptr aexpr = static_cast<AExpression::Ptr>(*$4);
420                 delete $4;
421                 
422                 String name = aexpr->Evaluate(m_ModuleScope);
423
424                 ConfigItem::Ptr oldItem = ConfigItem::GetObject($3, name);
425
426                 if (oldItem) {
427                         std::ostringstream msgbuf;
428                         msgbuf << "Object '" << name << "' of type '" << $3 << "' re-defined: " << di << "; previous definition: " << oldItem->GetDebugInfo();
429                         free($3);
430                         delete $5;
431                         BOOST_THROW_EXCEPTION(ConfigError(msgbuf.str()) << errinfo_debuginfo(di));
432                 }
433
434                 item->SetType($3);
435
436                 if (name.FindFirstOf("!") != String::NPos) {
437                         std::ostringstream msgbuf;
438                         msgbuf << "Name for object '" << name << "' of type '" << $3 << "' is invalid: Object names may not contain '!'";
439                         free($3);
440                         BOOST_THROW_EXCEPTION(ConfigError(msgbuf.str()) << errinfo_debuginfo(@4));
441                 }
442
443                 free($3);
444
445                 item->SetName(name);
446
447                 AExpression::Ptr exprl = static_cast<AExpression::Ptr>(*$5);
448                 delete $5;
449
450                 exprl->MakeInline();
451                 item->AddExpression(exprl);
452
453                 item->SetAbstract(m_Abstract);
454
455                 item->SetScope(m_ModuleScope);
456
457                 item->Compile()->Register();
458                 item.reset();
459         }
460         ;
461
462 object_declaration: T_OBJECT
463         | T_TEMPLATE
464         {
465                 m_Abstract = true;
466         }
467
468 lbinary_op: T_SET
469         | T_SET_PLUS
470         | T_SET_MINUS
471         | T_SET_MULTIPLY
472         | T_SET_DIVIDE
473         {
474                 $$ = $1;
475         }
476         ;
477
478 comma_or_semicolon: ',' | ';'
479         ;
480
481 lterm_items: lterm_items_inner
482         {
483                 $$ = $1;
484         }
485         | lterm_items_inner comma_or_semicolon
486         {
487                 $$ = $1;
488         }
489
490 lterm_items_inner: /* empty */
491         {
492                 $$ = new Array();
493         }
494         | lterm
495         {
496                 $$ = new Array();
497                 $$->Add(*$1);
498                 delete $1;
499         }
500         | lterm_items_inner comma_or_semicolon lterm
501         {
502                 if ($1)
503                         $$ = $1;
504                 else
505                         $$ = new Array();
506
507                 $$->Add(*$3);
508                 delete $3;
509         }
510         ;
511
512 lterm: identifier lbinary_op rterm
513         {
514                 AExpression::Ptr aexpr = static_cast<AExpression::Ptr>(*$3);
515                 $$ = new Value(make_shared<AExpression>($2, $1, aexpr, DebugInfoRange(@1, @3)));
516                 free($1);
517                 delete $3;
518         }
519         | identifier '[' T_STRING ']' lbinary_op rterm
520         {
521                 AExpression::Ptr subexpr = make_shared<AExpression>($5, $3, static_cast<AExpression::Ptr>(*$6), DebugInfoRange(@1, @6));
522                 free($3);
523                 delete $6;
524
525                 Array::Ptr subexprl = make_shared<Array>();
526                 subexprl->Add(subexpr);
527                 
528                 AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @6));
529                 $$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, $1, expr, DebugInfoRange(@1, @6)));
530                 free($1);
531         }
532         | identifier '.' T_IDENTIFIER lbinary_op rterm
533         {
534                 AExpression::Ptr subexpr = make_shared<AExpression>($4, $3, static_cast<AExpression::Ptr>(*$5), DebugInfoRange(@1, @5));
535                 free($3);
536                 delete $5;
537
538                 Array::Ptr subexprl = make_shared<Array>();
539                 subexprl->Add(subexpr);
540
541                 AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @5));
542                 $$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, $1, expr, DebugInfoRange(@1, @5)));
543                 free($1);
544         }
545         | rterm
546         {
547                 $$ = $1;
548         }
549         ;
550
551 rbinary_op: T_PLUS
552         | T_MINUS
553         | T_MULTIPLY
554         | T_DIVIDE_OP
555         | T_BINARY_AND
556         | T_BINARY_OR
557         | T_LESS_THAN
558         | T_GREATER_THAN
559         | T_LESS_THAN_OR_EQUAL
560         | T_GREATER_THAN_OR_EQUAL
561         | T_EQUAL
562         | T_NOT_EQUAL
563         | T_IN
564         | T_NOT_IN
565         | T_LOGICAL_AND
566         | T_LOGICAL_OR
567         | T_SHIFT_LEFT
568         | T_SHIFT_RIGHT
569         {
570                 $$ = $1;
571         }
572         ;
573         
574 rterm_items: rterm_items_inner
575         {
576                 $$ = $1;
577         }
578         | rterm_items_inner ','
579         {
580                 $$ = $1;
581         }
582         ;
583
584 rterm_items_inner: /* empty */
585         {
586                 $$ = new Array();
587         }
588         | rterm
589         {
590                 $$ = new Array();
591                 $$->Add(*$1);
592                 delete $1;
593         }
594         | rterm_items_inner ',' rterm
595         {
596                 if ($1)
597                         $$ = $1;
598                 else
599                         $$ = new Array();
600
601                 $$->Add(*$3);
602                 delete $3;
603         }
604         ;
605
606 rbinary_op: '+'
607         {
608                 $$ = &AExpression::OpAdd;
609         }
610         ;
611
612 rterm_scope: '{' lterm_items '}'
613         {
614                 $$ = new Value(make_shared<AExpression>(&AExpression::OpDict, Array::Ptr($2), DebugInfoRange(@1, @3)));
615         }
616         ;
617
618 rterm: T_STRING
619         {
620                 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, $1, @1));
621                 free($1);
622         }
623         | T_NUMBER
624         {
625                 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, $1, @1));
626         }
627         | T_NULL
628         {
629                 $$ = new Value(make_shared<AExpression>(&AExpression::OpLiteral, Empty, @1));
630         }
631         | rterm '.' T_IDENTIFIER
632         {
633                 $$ = new Value(make_shared<AExpression>(&AExpression::OpIndexer, static_cast<AExpression::Ptr>(*$1), make_shared<AExpression>(&AExpression::OpLiteral, $3, @3), DebugInfoRange(@1, @3)));
634                 delete $1;
635                 free($3);
636         }
637         | T_IDENTIFIER '(' rterm_items ')'
638         {
639                 Array::Ptr arguments = Array::Ptr($3);
640                 $$ = new Value(make_shared<AExpression>(&AExpression::OpFunctionCall, $1, make_shared<AExpression>(&AExpression::OpLiteral, arguments, @3), DebugInfoRange(@1, @4)));
641                 free($1);
642         }
643         | T_IMPORT rterm
644         {
645                 AExpression::Ptr avar = make_shared<AExpression>(&AExpression::OpVariable, "__type", DebugInfoRange(@1, @2));
646                 AExpression::Ptr aexpr = static_cast<AExpression::Ptr>(*$2);
647                 delete $2;
648                 $$ = new Value(make_shared<AExpression>(&AExpression::OpImport, avar, aexpr, DebugInfoRange(@1, @2)));
649         }
650         | T_IDENTIFIER
651         {
652                 $$ = new Value(make_shared<AExpression>(&AExpression::OpVariable, $1, @1));
653                 free($1);
654         }
655         | '!' rterm
656         {
657                 $$ = new Value(make_shared<AExpression>(&AExpression::OpNegate, static_cast<AExpression::Ptr>(*$2), DebugInfoRange(@1, @2)));
658                 delete $2;
659         }
660         | '~' rterm
661         {
662                 $$ = new Value(make_shared<AExpression>(&AExpression::OpNegate, static_cast<AExpression::Ptr>(*$2), DebugInfoRange(@1, @2)));
663                 delete $2;
664         }
665         | rterm '[' rterm ']'
666         {
667                 $$ = new Value(make_shared<AExpression>(&AExpression::OpIndexer, static_cast<AExpression::Ptr>(*$1), static_cast<AExpression::Ptr>(*$3), DebugInfoRange(@1, @4)));
668                 delete $1;
669                 free($3);
670         }
671         | '[' rterm_items ']'
672         {
673                 $$ = new Value(make_shared<AExpression>(&AExpression::OpArray, Array::Ptr($2), DebugInfoRange(@1, @3)));
674         }
675         | rterm_scope
676         {
677                 $$ = $1;
678         }
679         | '(' rterm ')'
680         {
681                 $$ = $2;
682         }
683         | rterm rbinary_op rterm
684         {
685                 $$ = new Value(make_shared<AExpression>($2, static_cast<AExpression::Ptr>(*$1), static_cast<AExpression::Ptr>(*$3), DebugInfoRange(@1, @3)));
686                 delete $1;
687                 delete $3;
688         }
689         ;
690
691 optional_template: /* empty */
692         | T_TEMPLATE
693         ;
694
695 apply: T_APPLY optional_template identifier identifier T_TO identifier T_WHERE rterm
696         {
697                 if (!ApplyRule::IsValidCombination($3, $6)) {
698                         BOOST_THROW_EXCEPTION(ConfigError("'apply' cannot be used with types '" + String($3) + "' and '" + String($6) + "'.") << errinfo_debuginfo(@1));
699                 }
700
701                 Array::Ptr arguments = make_shared<Array>();
702                 arguments->Add(*$8);
703                 delete $8;
704
705                 AExpression::Ptr aexpr = make_shared<AExpression>(&AExpression::OpFunctionCall, "bool", make_shared<AExpression>(&AExpression::OpLiteral, arguments, @8), @8);
706
707                 ApplyRule::AddRule($3, $4, $6, aexpr, DebugInfoRange(@1, @8), m_ModuleScope);
708         }
709 %%