]> granicus.if.org Git - icinga2/commitdiff
Fix some more shift/reduce conflicts
authorGunnar Beutner <gunnar.beutner@netways.de>
Sun, 23 Nov 2014 11:06:47 +0000 (12:06 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sun, 23 Nov 2014 11:06:47 +0000 (12:06 +0100)
refs #7800

lib/config/config_lexer.ll
lib/config/config_parser.yy
lib/config/configcompiler.cpp
lib/config/configcompiler.hpp

index acf8986828ff5e2b788f5a3fdd14e57fa15704fe..14ce03a0da4c8af2a6895f58ec964821699e3a08 100644 (file)
@@ -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];
 
 %%
index 48f232f00a6356313f41ed305210c11b6cc6e611..e2db1011953564d9f7ae24f49a03c055fc94b18e 100644 (file)
@@ -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));
index cd39617a0ae964b89236e8dbeab878d69afaadce..925e51fb91636ae42b8e3cdc947451e82d822ccf 100644 (file)
@@ -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();
 }
index ee63c8061c1be0d8995969362617f4188aab3f0f..0de5330cf080ae4f49d358d61c9ef8d3f02a2d9f 100644 (file)
 #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>