From 30f5de3dc4d96c5a92f9bb6e222cb39febd428cd Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 31 May 2012 09:14:44 +0200 Subject: [PATCH] Refactored parser. --- components/configfile/configcontext.cpp | 5 ++-- components/configfile/configcontext.h | 30 +++++++++++++++++++++--- components/configfile/configfile.vcxproj | 9 +++++++ components/configfile/i2-configfile.h | 1 + components/configfile/icinga_lexer.ll | 10 ++++---- components/configfile/icinga_parser.yy | 5 ++-- 6 files changed, 46 insertions(+), 14 deletions(-) diff --git a/components/configfile/configcontext.cpp b/components/configfile/configcontext.cpp index 1abfa20a1..263c77c5d 100644 --- a/components/configfile/configcontext.cpp +++ b/components/configfile/configcontext.cpp @@ -1,7 +1,6 @@ -#include -#include "configcontext.h" +#include "i2-configfile.h" -using namespace std; +using namespace icinga; ConfigContext::ConfigContext(istream *input) { diff --git a/components/configfile/configcontext.h b/components/configfile/configcontext.h index 4d4ada0b2..2d49b300c 100644 --- a/components/configfile/configcontext.h +++ b/components/configfile/configcontext.h @@ -1,13 +1,35 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + #ifndef CONFIGCONTEXT_H #define CONFIGCONTEXT_H +namespace icinga +{ + class ConfigContext { public: - ConfigContext(std::istream *input = &std::cin); + ConfigContext(istream *input = &cin); virtual ~ConfigContext(void); - std::istream *Input; + istream *Input; void *Scanner; private: @@ -15,6 +37,8 @@ private: void DestroyScanner(void); }; -int icingaparse(ConfigContext *context); +} + +int yyparse(icinga::ConfigContext *context); #endif /* CONFIGCONTEXT_H */ diff --git a/components/configfile/configfile.vcxproj b/components/configfile/configfile.vcxproj index 74e474d15..698e3a238 100644 --- a/components/configfile/configfile.vcxproj +++ b/components/configfile/configfile.vcxproj @@ -11,11 +11,20 @@ + + + + + + + + + {E58F1DA7-B723-412B-B2B7-7FF58E2A944E} diff --git a/components/configfile/i2-configfile.h b/components/configfile/i2-configfile.h index 25dbe9334..96776dee3 100644 --- a/components/configfile/i2-configfile.h +++ b/components/configfile/i2-configfile.h @@ -30,6 +30,7 @@ #include #include +#include "configcontext.h" #include "configfilecomponent.h" #endif /* I2CONFIGFILECOMPONENT_H */ diff --git a/components/configfile/icinga_lexer.ll b/components/configfile/icinga_lexer.ll index 84170465b..89d33cd76 100644 --- a/components/configfile/icinga_lexer.ll +++ b/components/configfile/icinga_lexer.ll @@ -1,7 +1,7 @@ %{ -#include -#include "configcontext.h" -#include "icinga_parser.h" +#include "i2-configfile.h" + +using namespace icinga; #define YY_EXTRA_TYPE ConfigContext * #define YY_USER_ACTION yylloc->first_line = yylineno; @@ -11,13 +11,11 @@ do { \ yyextra->Input->read(buf, max_size); \ result = yyextra->Input->gcount(); \ } while (0) - -#define YY_NO_UNISTD_H %} %option reentrant noyywrap yylineno %option bison-bridge bison-locations -%option never-interactive +%option never-interactive nounistd %x IN_C_COMMENT diff --git a/components/configfile/icinga_parser.yy b/components/configfile/icinga_parser.yy index 744172ec9..7fcfe96e9 100644 --- a/components/configfile/icinga_parser.yy +++ b/components/configfile/icinga_parser.yy @@ -28,8 +28,9 @@ %token T_INHERITS %{ -#include -#include "configcontext.h" +#include "i2-configfile.h" + +using namespace icinga; int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);