Merge branch 'master' of github.com:gunnarbeutner/strawberry

Conflicts:
	dyntest/dyntest.cpp
This commit is contained in:
Gunnar Beutner 2012-05-31 08:58:22 +02:00
commit e7169fdf8a
9 changed files with 269 additions and 0 deletions

View File

@ -7,6 +7,8 @@ SUBDIRS = \
compat \
third-party \
base \
dyn \
dyntest \
jsonrpc \
icinga \
components \

View File

@ -3,9 +3,17 @@
pkglib_LTLIBRARIES = \
configfile.la
BUILD_SOURCES = icinga_parser.h
AM_YFLAGS = -d
configfile_la_SOURCES = \
configcontext.cpp \
configcontext.h \
configfilecomponent.cpp \
configfilecomponent.h \
icinga_lexer.ll \
icinga_parser.yy \
i2-configfile.h
configfile_la_CPPFLAGS = \

View File

@ -0,0 +1,16 @@
#include <iostream>
#include "configcontext.h"
using namespace std;
ConfigContext::ConfigContext(istream *input)
{
Input = input;
InitializeScanner();
}
ConfigContext::~ConfigContext(void)
{
DestroyScanner();
}

View File

@ -0,0 +1,20 @@
#ifndef CONFIGCONTEXT_H
#define CONFIGCONTEXT_H
class ConfigContext
{
public:
ConfigContext(std::istream *input = &std::cin);
virtual ~ConfigContext(void);
std::istream *Input;
void *Scanner;
private:
void InitializeScanner(void);
void DestroyScanner(void);
};
int icingaparse(ConfigContext *context);
#endif /* CONFIGCONTEXT_H */

View File

@ -0,0 +1,64 @@
%{
#include <iostream>
#include "configcontext.h"
#include "icinga.tab.h"
#define YY_EXTRA_TYPE ConfigContext *
#define YY_USER_ACTION yylloc->first_line = yylineno;
#define YY_INPUT(buf, result, max_size) \
do { \
yyextra->Input->read(buf, max_size); \
result = yyextra->Input->gcount(); \
} while (0)
%}
%option reentrant noyywrap yylineno
%option prefix="icinga"
%option bison-bridge bison-locations
%x IN_C_COMMENT
%%
abstract return T_ABSTRACT;
local return T_LOCAL;
object return T_OBJECT;
include return T_INCLUDE;
inherits return T_INHERITS;
[a-zA-Z][a-zA-Z0-9]* return T_IDENTIFIER;
\"[^\"]+\" { yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING; }
[0-9]+ { yylval->num = atoi(yytext); return T_NUMBER; }
\{ return T_OPEN_BRACE;
\} return T_CLOSE_BRACE;
\[ return T_OPEN_BRACKET;
\] return T_CLOSE_BRACKET;
, return T_COMMA;
= return T_EQUAL;
<INITIAL>{
"/*" BEGIN(IN_C_COMMENT);
}
<IN_C_COMMENT>{
"*/" BEGIN(INITIAL);
[^*]+ /* ignore comment */
"*" /* ignore star */
}
\/\/[^\n]+ /* ignore C++-style comments */
#[^\n]+ /* ignore shell-style comments */
[ \t\n]+ /* ignore whitespace */
%%
void ConfigContext::InitializeScanner(void)
{
yylex_init(&Scanner);
yyset_extra(this, Scanner);
}
void ConfigContext::DestroyScanner(void)
{
yylex_destroy(Scanner);
}

View File

@ -0,0 +1,105 @@
%pure-parser
%name-prefix="icinga"
%locations
%defines
%error-verbose
%parse-param { ConfigContext *context }
%lex-param { void *scanner }
%union {
char *text;
int num;
}
%token <text> T_STRING
%token <num> T_NUMBER
%token T_IDENTIFIER
%token T_OPEN_BRACE
%token T_CLOSE_BRACE
%token T_OPEN_BRACKET
%token T_CLOSE_BRACKET
%token T_EQUAL
%token T_COMMA
%token T_ABSTRACT
%token T_LOCAL
%token T_OBJECT
%token T_INCLUDE
%token T_INHERITS
%{
#include <iostream>
#include "configcontext.h"
int icingalex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
void icingaerror(YYLTYPE *locp, ConfigContext *context, const char *err)
{
std::cout << locp->first_line << ":" << locp->first_column
<< "-"
<< locp->last_line << ":" << locp->last_column
<< ": " << err << std::endl;
}
#define scanner context->Scanner
%}
%%
statements: /* empty */
| statements statement
;
statement: object | include
;
include: T_INCLUDE T_STRING
;
object: attributes_list object_declaration
| object_declaration
;
object_declaration: T_OBJECT T_IDENTIFIER T_STRING inherits_specifier dictionary
;
attributes_list: attributes_list attribute
| attribute
;
attribute: T_ABSTRACT
| T_LOCAL
;
inherits_list: T_STRING
| inherits_list T_COMMA T_STRING
;
inherits_specifier: /* empty */
| T_INHERITS inherits_list
;
dictionary: T_OPEN_BRACE nvpairs T_CLOSE_BRACE
;
nvpairs: /* empty */
| nvpair
| nvpairs T_COMMA nvpair
;
nvpair: T_IDENTIFIER T_EQUAL value
;
value: T_STRING | T_NUMBER | array | dictionary
;
array: T_OPEN_BRACKET arrayitems T_CLOSE_BRACKET
;
arrayitems:
/* empty */
| value
| arrayitems T_COMMA value
;
%%

View File

@ -46,6 +46,8 @@ DX_PS_FEATURE(OFF)
DX_INIT_DOXYGEN([icinga], [Doxyfile], [doc])
AC_PROG_INSTALL
AM_PROG_LEX
AC_PROG_YACC
AC_PROG_LIBTOOL
AX_CXX_COMPILE_STDCXX_0X
AX_CXX_GCC_ABI_DEMANGLE
@ -71,6 +73,8 @@ components/configfile/Makefile
components/configrpc/Makefile
components/demo/Makefile
components/discovery/Makefile
dyn/Makefile
dyntest/Makefile
icinga/Makefile
icinga-app/Makefile
jsonrpc/Makefile

28
dyn/Makefile.am Normal file
View File

@ -0,0 +1,28 @@
## Process this file with automake to produce Makefile.in
pkglib_LTLIBRARIES = \
libdyn.la
libdyn_la_SOURCES = \
i2-dyn.h \
dynamicobject.cpp \
dynamicobject.h \
objectset.cpp \
objectset.h \
objectmap.cpp \
objectmap.h
libdyn_la_CPPFLAGS = \
-DI2_DYN_BUILD \
$(BOOST_CPPFLAGS) \
-I${top_srcdir}/base
libdyn_la_LDFLAGS = \
$(BOOST_LDFLAGS) \
-no-undefined \
@RELEASE_INFO@ \
@VERSION_INFO@
libdyn_la_LIBADD = \
${top_builddir}/base/libbase.la

22
dyntest/Makefile.am Normal file
View File

@ -0,0 +1,22 @@
## Process this file with automake to produce Makefile.in
bin_PROGRAMS = \
dyntest
dyntest_SOURCES = \
dyntest.cpp
dyntest_CPPFLAGS = \
-DI2_DYNTEST_BUILD \
$(BOOST_CPPFLAGS) \
-I${top_srcdir}/base \
-I${top_srcdir}/dyn \
-I${top_srcdir}
dyntest_LDFLAGS = \
$(BOOST_LDFLAGS)
dyntest_LDADD = \
${top_builddir}/base/libbase.la \
${top_builddir}/dyn/libdyn.la