2013-10-26 09:41:45 +02: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"
|
2013-10-26 09:41:45 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-11-03 12:40:39 +01:00
|
|
|
#define YYLTYPE icinga::ClassDebugInfo
|
|
|
|
|
|
|
|
#include "class_parser.hh"
|
|
|
|
|
2013-10-26 09:41:45 +02:00
|
|
|
#define YY_EXTRA_TYPE ClassCompiler *
|
2013-11-08 11:17:46 +01:00
|
|
|
#define YY_USER_ACTION \
|
|
|
|
do { \
|
|
|
|
yylloc->path = yyextra->GetPath(); \
|
|
|
|
yylloc->first_line = yylineno; \
|
|
|
|
yylloc->first_column = yycolumn; \
|
|
|
|
yylloc->last_line = yylineno; \
|
|
|
|
yylloc->last_column = yycolumn + yyleng - 1; \
|
|
|
|
yycolumn += yyleng; \
|
2013-10-26 09:41:45 +02:00
|
|
|
} while (0);
|
|
|
|
|
|
|
|
#define YY_INPUT(buf, result, max_size) \
|
|
|
|
do { \
|
|
|
|
result = yyextra->ReadInput(buf, max_size); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
struct lex_buf {
|
|
|
|
char *buf;
|
|
|
|
size_t size;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void lb_init(lex_buf *lb)
|
|
|
|
{
|
|
|
|
lb->buf = NULL;
|
|
|
|
lb->size = 0;
|
|
|
|
}
|
|
|
|
|
2014-05-22 09:02:44 +02:00
|
|
|
/*static void lb_cleanup(lex_buf *lb)
|
2013-10-26 09:41:45 +02:00
|
|
|
{
|
|
|
|
free(lb->buf);
|
2014-05-22 09:02:44 +02:00
|
|
|
}*/
|
2013-10-26 09:41:45 +02:00
|
|
|
|
|
|
|
static void lb_append_char(lex_buf *lb, char new_char)
|
|
|
|
{
|
|
|
|
const size_t block_size = 64;
|
|
|
|
|
|
|
|
size_t old_blocks = (lb->size + (block_size - 1)) / block_size;
|
|
|
|
size_t new_blocks = ((lb->size + 1) + (block_size - 1)) / block_size;
|
|
|
|
|
|
|
|
if (old_blocks != new_blocks) {
|
|
|
|
char *new_buf = (char *)realloc(lb->buf, new_blocks * block_size);
|
|
|
|
|
|
|
|
if (new_buf == NULL && new_blocks > 0)
|
|
|
|
throw std::bad_alloc();
|
|
|
|
|
|
|
|
lb->buf = new_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
lb->size++;
|
|
|
|
lb->buf[lb->size - 1] = new_char;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *lb_steal(lex_buf *lb)
|
|
|
|
{
|
|
|
|
lb_append_char(lb, '\0');
|
|
|
|
|
|
|
|
char *buf = lb->buf;
|
|
|
|
lb->buf = NULL;
|
|
|
|
lb->size = 0;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
%}
|
|
|
|
|
|
|
|
%option reentrant noyywrap yylineno
|
|
|
|
%option bison-bridge bison-locations
|
|
|
|
%option never-interactive nounistd
|
2014-11-06 06:23:25 +01:00
|
|
|
%option noinput nounput
|
2013-10-26 09:41:45 +02:00
|
|
|
|
|
|
|
%x HEREDOC
|
2014-10-17 19:44:31 +02:00
|
|
|
%x C_COMMENT
|
2013-10-26 09:41:45 +02:00
|
|
|
|
|
|
|
%%
|
|
|
|
lex_buf string_buf;
|
|
|
|
|
|
|
|
\{\{\{ { lb_init(&string_buf); BEGIN(HEREDOC); }
|
|
|
|
|
|
|
|
<HEREDOC>\}\}\} {
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
|
|
|
|
lb_append_char(&string_buf, '\0');
|
|
|
|
|
|
|
|
yylval->text = lb_steal(&string_buf);
|
|
|
|
|
|
|
|
return T_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
<HEREDOC>(.|\n) { lb_append_char(&string_buf, yytext[0]); }
|
|
|
|
|
2014-10-17 19:44:31 +02:00
|
|
|
"/*" { BEGIN(C_COMMENT); }
|
|
|
|
|
|
|
|
<C_COMMENT>{
|
|
|
|
"*/" { BEGIN(INITIAL); }
|
|
|
|
[^*] /* ignore comment */
|
|
|
|
"*" /* ignore star */
|
|
|
|
}
|
|
|
|
|
|
|
|
<C_COMMENT><<EOF>> {
|
|
|
|
fprintf(stderr, "End-of-file while in comment.\n");
|
|
|
|
yyterminate();
|
|
|
|
}
|
|
|
|
\/\/[^\n]* /* ignore C++-style comments */
|
2013-10-26 09:41:45 +02:00
|
|
|
[ \t\r\n] /* ignore whitespace */
|
|
|
|
|
|
|
|
#include { return T_INCLUDE; }
|
2015-08-25 13:53:43 +02:00
|
|
|
#impl_include { return T_IMPL_INCLUDE; }
|
2013-10-26 09:41:45 +02:00
|
|
|
class { return T_CLASS; }
|
|
|
|
namespace { return T_NAMESPACE; }
|
|
|
|
code { return T_CODE; }
|
2015-02-25 12:43:03 +01:00
|
|
|
load_after { return T_LOAD_AFTER; }
|
2018-04-26 15:53:11 +02:00
|
|
|
activation_priority { return T_ACTIVATION_PRIORITY; }
|
2015-08-04 14:47:44 +02:00
|
|
|
library { return T_LIBRARY; }
|
2013-12-18 10:18:57 +01:00
|
|
|
abstract { yylval->num = TAAbstract; return T_CLASS_ATTRIBUTE; }
|
2016-03-29 12:45:22 +02:00
|
|
|
vararg_constructor { yylval->num = TAVarArgConstructor; return T_CLASS_ATTRIBUTE; }
|
2013-10-26 09:41:45 +02:00
|
|
|
config { yylval->num = FAConfig; return T_FIELD_ATTRIBUTE; }
|
|
|
|
state { yylval->num = FAState; return T_FIELD_ATTRIBUTE; }
|
|
|
|
enum { yylval->num = FAEnum; return T_FIELD_ATTRIBUTE; }
|
2014-10-17 19:44:31 +02:00
|
|
|
get_protected { yylval->num = FAGetProtected; return T_FIELD_ATTRIBUTE; }
|
|
|
|
set_protected { yylval->num = FASetProtected; return T_FIELD_ATTRIBUTE; }
|
2013-10-26 09:41:45 +02:00
|
|
|
protected { yylval->num = FAGetProtected | FASetProtected; return T_FIELD_ATTRIBUTE; }
|
2015-02-09 08:50:17 +01:00
|
|
|
no_storage { yylval->num = FANoStorage; return T_FIELD_ATTRIBUTE; }
|
2015-10-20 08:20:35 +02:00
|
|
|
no_user_modify { yylval->num = FANoUserModify; return T_FIELD_ATTRIBUTE; }
|
|
|
|
no_user_view { yylval->num = FANoUserView; return T_FIELD_ATTRIBUTE; }
|
2017-10-16 15:32:57 +02:00
|
|
|
deprecated { yylval->num = FADeprecated; return T_FIELD_ATTRIBUTE; }
|
2017-11-15 09:47:23 +01:00
|
|
|
get_virtual { yylval->num = FAGetVirtual; return T_FIELD_ATTRIBUTE; }
|
|
|
|
set_virtual { yylval->num = FASetVirtual; return T_FIELD_ATTRIBUTE; }
|
|
|
|
virtual { yylval->num = FAGetVirtual | FASetVirtual; return T_FIELD_ATTRIBUTE; }
|
2015-09-22 09:42:30 +02:00
|
|
|
navigation { return T_NAVIGATION; }
|
2014-11-30 23:32:13 +01:00
|
|
|
validator { return T_VALIDATOR; }
|
|
|
|
required { return T_REQUIRED; }
|
|
|
|
name { return T_NAME; }
|
2015-08-25 13:53:43 +02:00
|
|
|
array { return T_ARRAY; }
|
2013-10-26 09:41:45 +02:00
|
|
|
default { yylval->num = FTDefault; return T_FIELD_ACCESSOR_TYPE; }
|
2014-10-17 19:44:31 +02:00
|
|
|
get { yylval->num = FTGet; return T_FIELD_ACCESSOR_TYPE; }
|
|
|
|
set { yylval->num = FTSet; return T_FIELD_ACCESSOR_TYPE; }
|
2015-08-25 13:53:43 +02:00
|
|
|
track { yylval->num = FTTrack; return T_FIELD_ACCESSOR_TYPE; }
|
2015-09-22 09:42:30 +02:00
|
|
|
navigate { yylval->num = FTNavigate; return T_FIELD_ACCESSOR_TYPE; }
|
2013-10-26 09:41:45 +02:00
|
|
|
\"[^\"]+\" { yylval->text = strdup(yytext + 1); yylval->text[strlen(yylval->text) - 1] = '\0'; return T_STRING; }
|
2015-09-22 09:42:30 +02:00
|
|
|
\<[^ \>]*\> { yylval->text = strdup(yytext + 1); yylval->text[strlen(yylval->text) - 1] = '\0'; return T_ANGLE_STRING; }
|
2013-10-26 09:41:45 +02:00
|
|
|
[a-zA-Z_][:a-zA-Z0-9\-_]* { yylval->text = strdup(yytext); return T_IDENTIFIER; }
|
2018-04-26 15:53:11 +02:00
|
|
|
-?[0-9]+(\.[0-9]+)? { yylval->num = strtod(yytext, NULL); return T_NUMBER; }
|
2013-10-26 09:41:45 +02:00
|
|
|
|
|
|
|
. return yytext[0];
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
void ClassCompiler::InitializeScanner(void)
|
|
|
|
{
|
|
|
|
yylex_init(&m_Scanner);
|
|
|
|
yyset_extra(this, m_Scanner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassCompiler::DestroyScanner(void)
|
|
|
|
{
|
|
|
|
yylex_destroy(m_Scanner);
|
|
|
|
}
|