Refactored parser.

This commit is contained in:
Gunnar Beutner 2012-05-31 09:14:44 +02:00
parent 4bd4280737
commit 30f5de3dc4
6 changed files with 46 additions and 14 deletions

View File

@ -1,7 +1,6 @@
#include <iostream>
#include "configcontext.h"
#include "i2-configfile.h"
using namespace std;
using namespace icinga;
ConfigContext::ConfigContext(istream *input)
{

View File

@ -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 */

View File

@ -11,11 +11,20 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="configcontext.cpp" />
<ClCompile Include="configfilecomponent.cpp" />
<ClCompile Include="icinga_lexer.cc" />
<ClCompile Include="icinga_parser.cc" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="configcontext.h" />
<ClInclude Include="configfilecomponent.h" />
<ClInclude Include="i2-configfile.h" />
<ClInclude Include="icinga_parser.h" />
</ItemGroup>
<ItemGroup>
<None Include="icinga_lexer.ll" />
<None Include="icinga_parser.yy" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{E58F1DA7-B723-412B-B2B7-7FF58E2A944E}</ProjectGuid>

View File

@ -30,6 +30,7 @@
#include <i2-base.h>
#include <i2-icinga.h>
#include "configcontext.h"
#include "configfilecomponent.h"
#endif /* I2CONFIGFILECOMPONENT_H */

View File

@ -1,7 +1,7 @@
%{
#include <iostream>
#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

View File

@ -28,8 +28,9 @@
%token T_INHERITS
%{
#include <iostream>
#include "configcontext.h"
#include "i2-configfile.h"
using namespace icinga;
int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);