2013-11-03 12:40:39 +01:00
|
|
|
%{
|
2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-10-26 09:41:45 +02:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "classcompiler.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
2014-09-02 13:02:22 +02:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
using std::malloc;
|
|
|
|
using std::free;
|
|
|
|
using std::exit;
|
2013-10-26 09:41:45 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
#define YYLTYPE icinga::ClassDebugInfo
|
|
|
|
|
2013-11-03 12:40:39 +01:00
|
|
|
%}
|
2013-10-26 09:41:45 +02:00
|
|
|
|
|
|
|
%pure-parser
|
|
|
|
|
|
|
|
%locations
|
|
|
|
%defines
|
|
|
|
%error-verbose
|
|
|
|
|
|
|
|
%parse-param { ClassCompiler *context }
|
|
|
|
%lex-param { void *scanner }
|
|
|
|
|
|
|
|
%union {
|
|
|
|
char *text;
|
|
|
|
int num;
|
2014-11-30 23:32:13 +01:00
|
|
|
FieldType *type;
|
2013-10-26 09:41:45 +02:00
|
|
|
Field *field;
|
|
|
|
std::vector<Field> *fields;
|
|
|
|
Klass *klass;
|
|
|
|
FieldAccessor *fieldaccessor;
|
|
|
|
std::vector<FieldAccessor> *fieldaccessors;
|
2014-11-30 23:32:13 +01:00
|
|
|
Rule *rule;
|
|
|
|
std::vector<Rule> *rules;
|
|
|
|
Validator *validator;
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
|
|
|
|
2015-08-25 13:53:43 +02:00
|
|
|
%token T_INCLUDE "#include (T_INCLUDE)"
|
|
|
|
%token T_IMPL_INCLUDE "#impl_include (T_IMPL_INCLUDE)"
|
2013-10-26 09:41:45 +02:00
|
|
|
%token T_CLASS "class (T_CLASS)"
|
|
|
|
%token T_CODE "code (T_CODE)"
|
2015-02-25 12:43:03 +01:00
|
|
|
%token T_LOAD_AFTER "load_after (T_LOAD_AFTER)"
|
2018-04-26 15:53:11 +02:00
|
|
|
%token T_ACTIVATION_PRIORITY "activation_priority (T_ACTIVATION_PRIORITY)"
|
2015-08-04 14:47:44 +02:00
|
|
|
%token T_LIBRARY "library (T_LIBRARY)"
|
2013-10-26 09:41:45 +02:00
|
|
|
%token T_NAMESPACE "namespace (T_NAMESPACE)"
|
2014-11-30 23:32:13 +01:00
|
|
|
%token T_VALIDATOR "validator (T_VALIDATOR)"
|
|
|
|
%token T_REQUIRED "required (T_REQUIRED)"
|
2015-09-22 09:42:30 +02:00
|
|
|
%token T_NAVIGATION "navigation (T_NAVIGATION)"
|
2014-11-30 23:32:13 +01:00
|
|
|
%token T_NAME "name (T_NAME)"
|
2015-08-25 13:53:43 +02:00
|
|
|
%token T_ARRAY "array (T_ARRAY)"
|
2013-10-26 09:41:45 +02:00
|
|
|
%token T_STRING "string (T_STRING)"
|
|
|
|
%token T_ANGLE_STRING "angle_string (T_ANGLE_STRING)"
|
|
|
|
%token T_FIELD_ATTRIBUTE "field_attribute (T_FIELD_ATTRIBUTE)"
|
2013-12-18 10:18:57 +01:00
|
|
|
%token T_CLASS_ATTRIBUTE "class_attribute (T_CLASS_ATTRIBUTE)"
|
2013-10-26 09:41:45 +02:00
|
|
|
%token T_IDENTIFIER "identifier (T_IDENTIFIER)"
|
|
|
|
%token T_GET "get (T_GET)"
|
|
|
|
%token T_SET "set (T_SET)"
|
|
|
|
%token T_DEFAULT "default (T_DEFAULT)"
|
|
|
|
%token T_FIELD_ACCESSOR_TYPE "field_accessor_type (T_FIELD_ACCESSOR_TYPE)"
|
2018-04-26 15:53:11 +02:00
|
|
|
%token T_NUMBER "number (T_NUMBER)"
|
2013-10-26 09:41:45 +02:00
|
|
|
%type <text> T_IDENTIFIER
|
|
|
|
%type <text> T_STRING
|
|
|
|
%type <text> T_ANGLE_STRING
|
|
|
|
%type <text> identifier
|
|
|
|
%type <text> alternative_name_specifier
|
|
|
|
%type <text> inherits_specifier
|
2014-04-05 22:17:20 +02:00
|
|
|
%type <text> type_base_specifier
|
2013-10-26 09:41:45 +02:00
|
|
|
%type <text> include
|
|
|
|
%type <text> angle_include
|
2015-08-25 13:53:43 +02:00
|
|
|
%type <text> impl_include
|
|
|
|
%type <text> angle_impl_include
|
2013-10-26 09:41:45 +02:00
|
|
|
%type <text> code
|
|
|
|
%type <num> T_FIELD_ATTRIBUTE
|
2015-09-22 09:42:30 +02:00
|
|
|
%type <field> field_attribute
|
|
|
|
%type <field> field_attributes
|
|
|
|
%type <field> field_attribute_list
|
2013-10-26 09:41:45 +02:00
|
|
|
%type <num> T_FIELD_ACCESSOR_TYPE
|
2013-12-18 10:18:57 +01:00
|
|
|
%type <num> T_CLASS_ATTRIBUTE
|
|
|
|
%type <num> class_attribute_list
|
2014-11-30 23:32:13 +01:00
|
|
|
%type <type> field_type
|
2013-10-26 09:41:45 +02:00
|
|
|
%type <field> class_field
|
|
|
|
%type <fields> class_fields
|
|
|
|
%type <klass> class
|
|
|
|
%type <fieldaccessors> field_accessor_list
|
|
|
|
%type <fieldaccessors> field_accessors
|
|
|
|
%type <fieldaccessor> field_accessor
|
2014-11-30 23:32:13 +01:00
|
|
|
%type <rule> validator_rule
|
|
|
|
%type <rules> validator_rules
|
|
|
|
%type <validator> validator
|
2018-04-26 15:53:11 +02:00
|
|
|
%type <num> T_NUMBER
|
2013-10-26 09:41:45 +02:00
|
|
|
|
|
|
|
%{
|
|
|
|
|
|
|
|
int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
|
|
|
|
|
|
|
|
void yyerror(YYLTYPE *locp, ClassCompiler *, const char *err)
|
|
|
|
{
|
2017-12-19 15:50:05 +01:00
|
|
|
std::cerr << "in " << locp->path << " at " << locp->first_line << ":" << locp->first_column << "-"
|
|
|
|
<< locp->last_line << ":" << locp->last_column << ": " << err << std::endl;
|
2014-09-02 13:02:22 +02:00
|
|
|
std::exit(1);
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int yyparse(ClassCompiler *context);
|
|
|
|
|
|
|
|
void ClassCompiler::Compile(void)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
yyparse(this);
|
|
|
|
} catch (const std::exception& ex) {
|
|
|
|
std::cerr << "Exception: " << ex.what();
|
|
|
|
}
|
2014-11-30 23:32:13 +01:00
|
|
|
|
|
|
|
HandleMissingValidators();
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define scanner (context->GetScanner())
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
statements: /* empty */
|
|
|
|
| statements statement
|
|
|
|
;
|
|
|
|
|
|
|
|
statement: include
|
|
|
|
{
|
|
|
|
context->HandleInclude($1, yylloc);
|
2014-09-02 13:02:22 +02:00
|
|
|
std::free($1);
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
|
|
|
| angle_include
|
|
|
|
{
|
|
|
|
context->HandleAngleInclude($1, yylloc);
|
2014-09-02 13:02:22 +02:00
|
|
|
std::free($1);
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
2015-08-25 13:53:43 +02:00
|
|
|
| impl_include
|
|
|
|
{
|
|
|
|
context->HandleImplInclude($1, yylloc);
|
|
|
|
std::free($1);
|
|
|
|
}
|
|
|
|
| angle_impl_include
|
|
|
|
{
|
|
|
|
context->HandleAngleImplInclude($1, yylloc);
|
|
|
|
std::free($1);
|
|
|
|
}
|
2013-10-26 09:41:45 +02:00
|
|
|
| class
|
|
|
|
{
|
|
|
|
context->HandleClass(*$1, yylloc);
|
|
|
|
delete $1;
|
|
|
|
}
|
2014-11-30 23:32:13 +01:00
|
|
|
| validator
|
|
|
|
{
|
|
|
|
context->HandleValidator(*$1, yylloc);
|
|
|
|
delete $1;
|
|
|
|
}
|
2013-10-26 09:41:45 +02:00
|
|
|
| namespace
|
|
|
|
| code
|
|
|
|
{
|
|
|
|
context->HandleCode($1, yylloc);
|
2014-09-02 13:02:22 +02:00
|
|
|
std::free($1);
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
2015-08-04 14:47:44 +02:00
|
|
|
| library
|
2013-10-26 09:41:45 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
include: T_INCLUDE T_STRING
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
angle_include: T_INCLUDE T_ANGLE_STRING
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2015-08-25 13:53:43 +02:00
|
|
|
impl_include: T_IMPL_INCLUDE T_STRING
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
angle_impl_include: T_IMPL_INCLUDE T_ANGLE_STRING
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2013-10-26 09:41:45 +02:00
|
|
|
namespace: T_NAMESPACE identifier '{'
|
|
|
|
{
|
|
|
|
context->HandleNamespaceBegin($2, yylloc);
|
2014-09-02 13:02:22 +02:00
|
|
|
std::free($2);
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
|
|
|
statements '}'
|
|
|
|
{
|
|
|
|
context->HandleNamespaceEnd(yylloc);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
code: T_CODE T_STRING
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2015-08-04 14:47:44 +02:00
|
|
|
library: T_LIBRARY T_IDENTIFIER ';'
|
|
|
|
{
|
|
|
|
context->HandleLibrary($2, yylloc);
|
|
|
|
free($2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-04-05 22:17:20 +02:00
|
|
|
class: class_attribute_list T_CLASS T_IDENTIFIER inherits_specifier type_base_specifier '{' class_fields '}' ';'
|
2013-10-26 09:41:45 +02:00
|
|
|
{
|
|
|
|
$$ = new Klass();
|
|
|
|
|
2013-11-04 19:30:33 +01:00
|
|
|
$$->Name = $3;
|
2014-09-02 13:02:22 +02:00
|
|
|
std::free($3);
|
2013-10-26 09:41:45 +02:00
|
|
|
|
2013-11-04 19:30:33 +01:00
|
|
|
if ($4) {
|
|
|
|
$$->Parent = $4;
|
2014-09-02 13:02:22 +02:00
|
|
|
std::free($4);
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
|
|
|
|
2014-04-05 22:17:20 +02:00
|
|
|
if ($5) {
|
|
|
|
$$->TypeBase = $5;
|
2014-09-02 13:02:22 +02:00
|
|
|
std::free($5);
|
2014-04-05 22:17:20 +02:00
|
|
|
}
|
|
|
|
|
2013-12-18 10:18:57 +01:00
|
|
|
$$->Attributes = $1;
|
2013-11-04 19:30:33 +01:00
|
|
|
|
2016-08-27 12:17:10 +02:00
|
|
|
for (const Field& field : *$7) {
|
|
|
|
if (field.Attributes & FALoadDependency) {
|
|
|
|
$$->LoadDependencies.push_back(field.Name);
|
2018-04-26 15:53:11 +02:00
|
|
|
} else if (field.Attributes & FAActivationPriority) {
|
|
|
|
$$->ActivationPriority = field.Priority;
|
2015-02-25 12:43:03 +01:00
|
|
|
} else
|
2016-08-27 12:17:10 +02:00
|
|
|
$$->Fields.push_back(field);
|
2015-02-25 12:43:03 +01:00
|
|
|
}
|
|
|
|
|
2014-04-05 22:17:20 +02:00
|
|
|
delete $7;
|
2014-11-07 23:07:02 +01:00
|
|
|
|
|
|
|
ClassCompiler::OptimizeStructLayout($$->Fields);
|
2013-11-04 19:30:33 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2013-12-18 10:18:57 +01:00
|
|
|
class_attribute_list: /* empty */
|
2013-11-04 19:30:33 +01:00
|
|
|
{
|
2013-12-18 10:18:57 +01:00
|
|
|
$$ = 0;
|
2013-11-04 19:30:33 +01:00
|
|
|
}
|
2013-12-18 10:18:57 +01:00
|
|
|
| T_CLASS_ATTRIBUTE
|
2013-11-04 19:30:33 +01:00
|
|
|
{
|
2013-12-18 10:18:57 +01:00
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| class_attribute_list T_CLASS_ATTRIBUTE
|
|
|
|
{
|
|
|
|
$$ = $1 | $2;
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inherits_specifier: /* empty */
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
| ':' identifier
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-04-05 22:17:20 +02:00
|
|
|
type_base_specifier: /* empty */
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
| '<' identifier
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2013-10-26 09:41:45 +02:00
|
|
|
class_fields: /* empty */
|
|
|
|
{
|
|
|
|
$$ = new std::vector<Field>();
|
|
|
|
}
|
|
|
|
| class_fields class_field
|
|
|
|
{
|
|
|
|
$$->push_back(*$2);
|
|
|
|
delete $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-11-30 23:32:13 +01:00
|
|
|
field_type: identifier
|
|
|
|
{
|
|
|
|
$$ = new FieldType();
|
|
|
|
$$->IsName = false;
|
|
|
|
$$->TypeName = $1;
|
|
|
|
free($1);
|
|
|
|
}
|
|
|
|
| T_NAME '(' identifier ')'
|
|
|
|
{
|
|
|
|
$$ = new FieldType();
|
|
|
|
$$->IsName = true;
|
|
|
|
$$->TypeName = $3;
|
2015-08-25 13:53:43 +02:00
|
|
|
$$->ArrayRank = 0;
|
2014-11-30 23:32:13 +01:00
|
|
|
free($3);
|
|
|
|
}
|
2015-08-25 13:53:43 +02:00
|
|
|
| T_ARRAY '(' field_type ')'
|
|
|
|
{
|
|
|
|
$$ = $3;
|
|
|
|
$$->ArrayRank++;
|
|
|
|
}
|
2014-11-30 23:32:13 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
class_field: field_attribute_list field_type identifier alternative_name_specifier field_accessor_list ';'
|
2013-10-26 09:41:45 +02:00
|
|
|
{
|
2015-09-22 09:42:30 +02:00
|
|
|
Field *field = $1;
|
2013-10-26 09:41:45 +02:00
|
|
|
|
2015-03-11 16:06:58 +01:00
|
|
|
if ((field->Attributes & (FAConfig | FAState)) == 0)
|
|
|
|
field->Attributes |= FAEphemeral;
|
|
|
|
|
2014-11-30 23:32:13 +01:00
|
|
|
field->Type = *$2;
|
|
|
|
delete $2;
|
2013-10-26 09:41:45 +02:00
|
|
|
|
|
|
|
field->Name = $3;
|
2014-09-02 13:02:22 +02:00
|
|
|
std::free($3);
|
2013-10-26 09:41:45 +02:00
|
|
|
|
|
|
|
if ($4) {
|
|
|
|
field->AlternativeName = $4;
|
2014-09-02 13:02:22 +02:00
|
|
|
std::free($4);
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<FieldAccessor>::const_iterator it;
|
|
|
|
for (it = $5->begin(); it != $5->end(); it++) {
|
|
|
|
switch (it->Type) {
|
|
|
|
case FTGet:
|
|
|
|
field->GetAccessor = it->Accessor;
|
2015-02-09 08:50:17 +01:00
|
|
|
field->PureGetAccessor = it->Pure;
|
2013-10-26 09:41:45 +02:00
|
|
|
break;
|
|
|
|
case FTSet:
|
|
|
|
field->SetAccessor = it->Accessor;
|
2015-02-09 08:50:17 +01:00
|
|
|
field->PureSetAccessor = it->Pure;
|
2013-10-26 09:41:45 +02:00
|
|
|
break;
|
|
|
|
case FTDefault:
|
|
|
|
field->DefaultAccessor = it->Accessor;
|
|
|
|
break;
|
2015-08-25 13:53:43 +02:00
|
|
|
case FTTrack:
|
|
|
|
field->TrackAccessor = it->Accessor;
|
|
|
|
break;
|
2015-09-22 09:42:30 +02:00
|
|
|
case FTNavigate:
|
|
|
|
field->NavigateAccessor = it->Accessor;
|
|
|
|
field->PureNavigateAccessor = it->Pure;
|
|
|
|
break;
|
2015-08-25 13:53:43 +02:00
|
|
|
}
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
delete $5;
|
|
|
|
|
|
|
|
$$ = field;
|
|
|
|
}
|
2015-02-25 12:43:03 +01:00
|
|
|
| T_LOAD_AFTER identifier ';'
|
|
|
|
{
|
2018-01-04 04:25:35 +01:00
|
|
|
auto *field = new Field();
|
2015-02-25 12:43:03 +01:00
|
|
|
field->Attributes = FALoadDependency;
|
|
|
|
field->Name = $2;
|
|
|
|
std::free($2);
|
|
|
|
$$ = field;
|
|
|
|
}
|
2018-04-26 15:53:11 +02:00
|
|
|
| T_ACTIVATION_PRIORITY T_NUMBER ';'
|
|
|
|
{
|
|
|
|
auto *field = new Field();
|
|
|
|
field->Attributes = FAActivationPriority;
|
|
|
|
field->Priority = $2;
|
|
|
|
$$ = field;
|
|
|
|
}
|
2013-10-26 09:41:45 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
alternative_name_specifier: /* empty */
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
| '(' identifier ')'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
field_attribute_list: /* empty */
|
|
|
|
{
|
2015-09-22 09:42:30 +02:00
|
|
|
$$ = new Field();
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
|
|
|
| '[' field_attributes ']'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-11-30 23:32:13 +01:00
|
|
|
field_attribute: T_FIELD_ATTRIBUTE
|
|
|
|
{
|
2015-09-22 09:42:30 +02:00
|
|
|
$$ = new Field();
|
|
|
|
$$->Attributes = $1;
|
2014-11-30 23:32:13 +01:00
|
|
|
}
|
|
|
|
| T_REQUIRED
|
|
|
|
{
|
2015-09-22 09:42:30 +02:00
|
|
|
$$ = new Field();
|
|
|
|
$$->Attributes = FARequired;
|
|
|
|
}
|
|
|
|
| T_NAVIGATION '(' identifier ')'
|
|
|
|
{
|
|
|
|
$$ = new Field();
|
|
|
|
$$->Attributes = FANavigation;
|
|
|
|
$$->NavigationName = $3;
|
|
|
|
std::free($3);
|
|
|
|
}
|
|
|
|
| T_NAVIGATION
|
|
|
|
{
|
|
|
|
$$ = new Field();
|
|
|
|
$$->Attributes = FANavigation;
|
2014-11-30 23:32:13 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2013-10-26 09:41:45 +02:00
|
|
|
field_attributes: /* empty */
|
|
|
|
{
|
2015-09-22 09:42:30 +02:00
|
|
|
$$ = new Field();
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
2014-11-30 23:32:13 +01:00
|
|
|
| field_attributes ',' field_attribute
|
2013-10-26 09:41:45 +02:00
|
|
|
{
|
2015-09-22 09:42:30 +02:00
|
|
|
$$ = $1;
|
|
|
|
$$->Attributes |= $3->Attributes;
|
|
|
|
if (!$3->NavigationName.empty())
|
|
|
|
$$->NavigationName = $3->NavigationName;
|
|
|
|
delete $3;
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
2014-11-30 23:32:13 +01:00
|
|
|
| field_attribute
|
2013-10-26 09:41:45 +02:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
field_accessor_list: /* empty */
|
|
|
|
{
|
|
|
|
$$ = new std::vector<FieldAccessor>();
|
|
|
|
}
|
|
|
|
| '{' field_accessors '}'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
field_accessors: /* empty */
|
|
|
|
{
|
|
|
|
$$ = new std::vector<FieldAccessor>();
|
|
|
|
}
|
|
|
|
| field_accessors field_accessor
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->push_back(*$2);
|
|
|
|
delete $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
field_accessor: T_FIELD_ACCESSOR_TYPE T_STRING
|
|
|
|
{
|
2015-02-09 08:50:17 +01:00
|
|
|
$$ = new FieldAccessor(static_cast<FieldAccessorType>($1), $2, false);
|
2014-09-02 13:02:22 +02:00
|
|
|
std::free($2);
|
2013-10-26 09:41:45 +02:00
|
|
|
}
|
2015-02-09 08:50:17 +01:00
|
|
|
| T_FIELD_ACCESSOR_TYPE ';'
|
|
|
|
{
|
|
|
|
$$ = new FieldAccessor(static_cast<FieldAccessorType>($1), "", true);
|
|
|
|
}
|
2013-10-26 09:41:45 +02:00
|
|
|
;
|
|
|
|
|
2014-11-30 23:32:13 +01:00
|
|
|
validator_rules: /* empty */
|
|
|
|
{
|
|
|
|
$$ = new std::vector<Rule>();
|
|
|
|
}
|
|
|
|
| validator_rules validator_rule
|
|
|
|
{
|
|
|
|
$$->push_back(*$2);
|
|
|
|
delete $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
validator_rule: T_NAME '(' T_IDENTIFIER ')' identifier ';'
|
|
|
|
{
|
|
|
|
$$ = new Rule();
|
|
|
|
$$->Attributes = 0;
|
|
|
|
$$->IsName = true;
|
|
|
|
$$->Type = $3;
|
|
|
|
std::free($3);
|
|
|
|
$$->Pattern = $5;
|
|
|
|
std::free($5);
|
|
|
|
}
|
|
|
|
| T_IDENTIFIER identifier ';'
|
|
|
|
{
|
|
|
|
$$ = new Rule();
|
|
|
|
$$->Attributes = 0;
|
|
|
|
$$->IsName = false;
|
|
|
|
$$->Type = $1;
|
|
|
|
std::free($1);
|
|
|
|
$$->Pattern = $2;
|
|
|
|
std::free($2);
|
|
|
|
}
|
|
|
|
| T_NAME '(' T_IDENTIFIER ')' identifier '{' validator_rules '}' ';'
|
|
|
|
{
|
|
|
|
$$ = new Rule();
|
|
|
|
$$->Attributes = 0;
|
|
|
|
$$->IsName = true;
|
|
|
|
$$->Type = $3;
|
|
|
|
std::free($3);
|
|
|
|
$$->Pattern = $5;
|
|
|
|
std::free($5);
|
|
|
|
$$->Rules = *$7;
|
|
|
|
delete $7;
|
|
|
|
}
|
|
|
|
| T_IDENTIFIER identifier '{' validator_rules '}' ';'
|
|
|
|
{
|
|
|
|
$$ = new Rule();
|
|
|
|
$$->Attributes = 0;
|
|
|
|
$$->IsName = false;
|
|
|
|
$$->Type = $1;
|
|
|
|
std::free($1);
|
|
|
|
$$->Pattern = $2;
|
|
|
|
std::free($2);
|
|
|
|
$$->Rules = *$4;
|
|
|
|
delete $4;
|
|
|
|
}
|
|
|
|
| T_REQUIRED identifier ';'
|
|
|
|
{
|
|
|
|
$$ = new Rule();
|
|
|
|
$$->Attributes = RARequired;
|
|
|
|
$$->IsName = false;
|
|
|
|
$$->Type = "";
|
|
|
|
$$->Pattern = $2;
|
|
|
|
std::free($2);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
validator: T_VALIDATOR T_IDENTIFIER '{' validator_rules '}' ';'
|
|
|
|
{
|
|
|
|
$$ = new Validator();
|
|
|
|
|
|
|
|
$$->Name = $2;
|
|
|
|
std::free($2);
|
|
|
|
|
|
|
|
$$->Rules = *$4;
|
|
|
|
delete $4;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2013-10-26 09:41:45 +02:00
|
|
|
identifier: T_IDENTIFIER
|
|
|
|
| T_STRING
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|