]> granicus.if.org Git - icinga2/blobdiff - lib/config/config_lexer.ll
Fix escape sequence for backslashes
[icinga2] / lib / config / config_lexer.ll
index 5252f8d91a50dd8dd786e49bc0f96a97a8cc8545..3e238286ca3e79d130098d3a251f132643307eb7 100644 (file)
@@ -20,7 +20,6 @@
 
 #include "config/configcompiler.hpp"
 #include "config/typerule.hpp"
-#include "config/configcompilercontext.hpp"
 #include "config/expression.hpp"
 
 using namespace icinga;
@@ -28,7 +27,7 @@ using namespace icinga;
 #include "config/config_parser.hh"
 #include <sstream>
 
-#define YYLTYPE icinga::DebugInfo
+#define YYLTYPE icinga::CompilerDebugInfo
 
 #define YY_EXTRA_TYPE ConfigCompiler *
 #define YY_USER_ACTION                                         \
@@ -41,21 +40,6 @@ do {                                                 \
        yycolumn += yyleng;                             \
 } while (0);
 
-#define YYLLOC_DEFAULT(Current, Rhs, N)                                                        \
-       do                                                                              \
-               if (YYID (N)) {                                                         \
-                       (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;          \
-                       (Current).first_column = YYRHSLOC (Rhs, 1).first_column;        \
-                       (Current).last_line    = YYRHSLOC (Rhs, N).last_line;           \
-                       (Current).last_column  = YYRHSLOC (Rhs, N).last_column;         \
-               } else {                                                                \
-                       (Current).first_line   = (Current).last_line =                  \
-                           YYRHSLOC(Rhs, 0).last_line;                                 \
-                       (Current).first_column = (Current).last_column =                \
-                           YYRHSLOC(Rhs, 0).last_column;                               \
-               }                                                                       \
-       while (YYID(0))
-
 #define YY_INPUT(buf, result, max_size)                        \
 do {                                                   \
        result = yyextra->ReadInput(buf, max_size);     \
@@ -72,11 +56,21 @@ do {                                                        \
 %x HEREDOC
 
 %%
-\"                             { yyextra->m_LexBuffer.str(""); yyextra->m_LexBuffer.clear(); BEGIN(STRING); }
+\"                             {
+       yyextra->m_LexBuffer.str("");
+       yyextra->m_LexBuffer.clear();
+
+       yyextra->m_LocationBegin = *yylloc;
+
+       BEGIN(STRING);
+                               }
 
 <STRING>\"                     {
        BEGIN(INITIAL);
 
+       yylloc->FirstLine = yyextra->m_LocationBegin.FirstLine;
+       yylloc->FirstColumn = yyextra->m_LocationBegin.FirstColumn;
+
        std::string str = yyextra->m_LexBuffer.str();
        yylval->text = strdup(str.c_str());
 
@@ -84,7 +78,7 @@ do {                                                  \
                                }
 
 <STRING>\n                     {
-       BOOST_THROW_EXCEPTION(ConfigError("Unterminated string literal") << errinfo_debuginfo(*yylloc));
+       BOOST_THROW_EXCEPTION(ScriptError("Unterminated string literal", DebugInfoRange(yyextra->m_LocationBegin, *yylloc)));
                                }
 
 <STRING>\\[0-7]{1,3}           {
@@ -95,7 +89,7 @@ do {                                                  \
 
        if (result > 0xff) {
                /* error, constant is out-of-bounds */
-               BOOST_THROW_EXCEPTION(ConfigError("Constant is out of bounds: " + String(yytext)) << errinfo_debuginfo(*yylloc));
+               BOOST_THROW_EXCEPTION(ScriptError("Constant is out of bounds: " + String(yytext), *yylloc));
        }
 
        yyextra->m_LexBuffer << static_cast<char>(result);
@@ -105,15 +99,18 @@ do {                                                       \
        /* generate error - bad escape sequence; something
         * like '\48' or '\0777777'
         */
-       BOOST_THROW_EXCEPTION(ConfigError("Bad escape sequence found: " + String(yytext)) << errinfo_debuginfo(*yylloc));
+       BOOST_THROW_EXCEPTION(ScriptError("Bad escape sequence found: " + String(yytext), *yylloc));
                                }
-
 <STRING>\\n                    { yyextra->m_LexBuffer << "\n"; }
+<STRING>\\\\                   { yyextra->m_LexBuffer << "\\"; }
 <STRING>\\t                    { yyextra->m_LexBuffer << "\t"; }
 <STRING>\\r                    { yyextra->m_LexBuffer << "\r"; }
 <STRING>\\b                    { yyextra->m_LexBuffer << "\b"; }
 <STRING>\\f                    { yyextra->m_LexBuffer << "\f"; }
-<STRING>\\(.|\n)               { yyextra->m_LexBuffer << yytext[1]; }
+<STRING>\\\n                   { yyextra->m_LexBuffer << yytext[1]; }
+<STRING>\\.                    {
+       BOOST_THROW_EXCEPTION(ScriptError("Bad escape sequence found: " + String(yytext), *yylloc));
+                               }
 
 <STRING>[^\\\n\"]+             {
        char *yptr = yytext;
@@ -122,13 +119,25 @@ do {                                                      \
                yyextra->m_LexBuffer << *yptr++;
                               }
 
-<STRING><<EOF>>                        { BOOST_THROW_EXCEPTION(ConfigError("End-of-file while in string literal") << errinfo_debuginfo(*yylloc)); }
+<STRING><<EOF>>                        {
+       BOOST_THROW_EXCEPTION(ScriptError("End-of-file while in string literal", DebugInfoRange(yyextra->m_LocationBegin, *yylloc)));
+                               }
+
+\{\{\{                         {
+       yyextra->m_LexBuffer.str("");
+       yyextra->m_LexBuffer.clear();
+
+       yyextra->m_LocationBegin = *yylloc;
 
-\{\{\{                         { yyextra->m_LexBuffer.str(""); yyextra->m_LexBuffer.clear(); BEGIN(HEREDOC); }
+       BEGIN(HEREDOC);
+                               }
 
 <HEREDOC>\}\}\}                        {
        BEGIN(INITIAL);
 
+       yylloc->FirstLine = yyextra->m_LocationBegin.FirstLine;
+       yylloc->FirstColumn = yyextra->m_LocationBegin.FirstColumn;
+
        std::string str = yyextra->m_LexBuffer.str();
        yylval->text = strdup(str.c_str());
 
@@ -148,8 +157,8 @@ do {                                                        \
 }
 
 <C_COMMENT><<EOF>>              {
-               BOOST_THROW_EXCEPTION(ConfigError("End-of-file while in comment") << errinfo_debuginfo(*yylloc));
-                               }
+       BOOST_THROW_EXCEPTION(ScriptError("End-of-file while in comment", *yylloc));
+                               }
 
 
 \/\/[^\n]*                     /* ignore C++-style comments */
@@ -175,10 +184,11 @@ include                           return T_INCLUDE;
 include_recursive              return T_INCLUDE_RECURSIVE;
 library                                return T_LIBRARY;
 null                           return T_NULL;
-true                           { yylval->num = 1; return T_NUMBER; }
-false                          { yylval->num = 0; return T_NUMBER; }
+true                           { yylval->boolean = 1; return T_BOOLEAN; }
+false                          { yylval->boolean = 0; return T_BOOLEAN; }
 const                          return T_CONST;
-local                          return T_LOCAL;
+var                            return T_VAR;
+this                           return T_THIS;
 use                            return T_USE;
 apply                          return T_APPLY;
 to                             return T_TO;
@@ -186,13 +196,11 @@ where                             return T_WHERE;
 import                         return T_IMPORT;
 assign                         return T_ASSIGN;
 ignore                         return T_IGNORE;
-for                            return T_APPLY_FOR;
-__function                     return T_FUNCTION;
-__return                       return T_RETURN;
-__for                          return T_FOR;
-__signal                       return T_SIGNAL;
-__if                           return T_IF;
-__else                         return T_ELSE;
+function                       return T_FUNCTION;
+return                         return T_RETURN;
+for                            return T_FOR;
+if                             return T_IF;
+else                           return T_ELSE;
 =\>                            return T_FOLLOWS;
 \<\<                           return T_SHIFT_LEFT;
 \>\>                           return T_SHIFT_RIGHT;