From 9a49e085cda3ada1644ffd76512fd19b6749aa16 Mon Sep 17 00:00:00 2001
From: Gunnar Beutner <gunnar.beutner@netways.de>
Date: Sun, 23 Nov 2014 12:06:47 +0100
Subject: [PATCH] Fix some more shift/reduce conflicts

refs #7800
---
 lib/config/config_lexer.ll    |  1 +
 lib/config/config_parser.yy   | 20 ++++++++++----------
 lib/config/configcompiler.cpp |  2 +-
 lib/config/configcompiler.hpp |  8 ++++++++
 4 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/lib/config/config_lexer.ll b/lib/config/config_lexer.ll
index acf898682..14ce03a0d 100644
--- a/lib/config/config_lexer.ll
+++ b/lib/config/config_lexer.ll
@@ -287,6 +287,7 @@ in				return T_IN;
 }
 
 [\r\n]+				{ yycolumn -= strlen(yytext) - 1; if (!ignore_newlines) return T_NEWLINE; }
+<<EOF>>				{ if (!yyextra->m_Eof) { yyextra->m_Eof = true; return T_NEWLINE; } else { yyterminate(); } }
 .				return yytext[0];
 
 %%
diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy
index 48f232f00..e2db10119 100644
--- a/lib/config/config_parser.yy
+++ b/lib/config/config_parser.yy
@@ -1,5 +1,5 @@
 %{
- #define YYDEBUG 1
+#define YYDEBUG 1
  
 /******************************************************************************
  * Icinga 2                                                                   *
@@ -255,7 +255,8 @@ Expression *ConfigCompiler::Compile(void)
 	m_Expressions.push(std::vector<Expression *>());
 
 	try {
-		yyparse(this);
+		if (yyparse(this) != 0)
+			BOOST_THROW_EXCEPTION(ConfigError("Syntax error"));
 
 		DictExpression *expr = new DictExpression(m_Expressions.top());
 		m_Expressions.pop();
@@ -278,28 +279,27 @@ Expression *ConfigCompiler::Compile(void)
 %}
 
 %%
-statements: /* empty */
-	| statements statement
+statements: statement sep
+	| statements statement sep
 	;
 
 statement: type | library | constant
-	{ }
-	| newlines
 	{ }
 	| lterm
 	{
+		printf("lterm!\n");
 		m_Expressions.top().push_back($1);
 	}
 	;
 
-library: T_LIBRARY T_STRING sep
+library: T_LIBRARY T_STRING
 	{
 		context->HandleLibrary($2);
 		free($2);
 	}
 	;
 
-constant: T_CONST identifier T_SET rterm sep
+constant: T_CONST identifier T_SET rterm
 	{
 		VMFrame frame;
 		ScriptVariable::Ptr sv = ScriptVariable::Set($2, $4->Evaluate(frame));
@@ -329,7 +329,7 @@ type: T_TYPE identifier
 			m_Type->Register();
 		}
 	}
-	type_inherits_specifier typerulelist sep
+	type_inherits_specifier typerulelist
 	{
 		TypeRuleList::Ptr ruleList = *$5;
 		delete $5;
@@ -589,7 +589,7 @@ lterm: T_LOCAL indexer combined_set_op rterm
 		$$ = new SetExpression(*$1, $2, $3, false, DebugInfoRange(@1, @3));
 		delete $1;
 	}
-	| T_INCLUDE rterm sep
+	| T_INCLUDE rterm
 	{
 		VMFrame frame;
 		$$ = context->HandleInclude($2->Evaluate(frame), false, DebugInfoRange(@1, @2));
diff --git a/lib/config/configcompiler.cpp b/lib/config/configcompiler.cpp
index cd39617a0..925e51fb9 100644
--- a/lib/config/configcompiler.cpp
+++ b/lib/config/configcompiler.cpp
@@ -41,7 +41,7 @@ std::vector<String> ConfigCompiler::m_IncludeSearchDirs;
  * @param zone The zone.
  */
 ConfigCompiler::ConfigCompiler(const String& path, std::istream *input, const String& zone)
-	: m_Path(path), m_Input(input), m_Zone(zone)
+	: m_Path(path), m_Input(input), m_Zone(zone), m_Eof(false)
 {
 	InitializeScanner();
 }
diff --git a/lib/config/configcompiler.hpp b/lib/config/configcompiler.hpp
index ee63c8061..0de5330cf 100644
--- a/lib/config/configcompiler.hpp
+++ b/lib/config/configcompiler.hpp
@@ -29,6 +29,11 @@
 #include <iostream>
 #include <boost/function.hpp>
 
+typedef union YYSTYPE YYSTYPE;
+typedef void *yyscan_t;
+
+int yylex(YYSTYPE *context, icinga::DebugInfo *di, yyscan_t scanner);
+
 namespace icinga
 {
 
@@ -73,11 +78,14 @@ private:
 	String m_Zone;
 
 	void *m_Scanner;
+	bool m_Eof;
 
 	static std::vector<String> m_IncludeSearchDirs;
 
 	void InitializeScanner(void);
 	void DestroyScanner(void);
+
+	friend int ::yylex(YYSTYPE *context, icinga::DebugInfo *di, yyscan_t scanner);
 };
 
 class I2_CONFIG_API ConfigFragmentRegistry : public Registry<ConfigFragmentRegistry, String>