]> granicus.if.org Git - icinga2/blobdiff - lib/config/config_lexer.ll
Fix escape sequence for backslashes
[icinga2] / lib / config / config_lexer.ll
index 3adb48e0330a560fcd6929d7852e3d412348245d..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;
@@ -57,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());
 
@@ -69,7 +78,7 @@ do {                                                  \
                                }
 
 <STRING>\n                     {
-       BOOST_THROW_EXCEPTION(ScriptError("Unterminated string literal", *yylloc));
+       BOOST_THROW_EXCEPTION(ScriptError("Unterminated string literal", DebugInfoRange(yyextra->m_LocationBegin, *yylloc)));
                                }
 
 <STRING>\\[0-7]{1,3}           {
@@ -92,13 +101,16 @@ do {                                                       \
         */
        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;
@@ -107,13 +119,25 @@ do {                                                      \
                yyextra->m_LexBuffer << *yptr++;
                               }
 
-<STRING><<EOF>>                        { BOOST_THROW_EXCEPTION(ScriptError("End-of-file while in string literal", *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());
 
@@ -133,8 +157,8 @@ do {                                                        \
 }
 
 <C_COMMENT><<EOF>>              {
-               BOOST_THROW_EXCEPTION(ScriptError("End-of-file while in comment", *yylloc));
-                               }
+       BOOST_THROW_EXCEPTION(ScriptError("End-of-file while in comment", *yylloc));
+                               }
 
 
 \/\/[^\n]*                     /* ignore C++-style comments */
@@ -162,10 +186,9 @@ library                            return T_LIBRARY;
 null                           return T_NULL;
 true                           { yylval->boolean = 1; return T_BOOLEAN; }
 false                          { yylval->boolean = 0; return T_BOOLEAN; }
-const                          return T_GLOBAL;
-local                          return T_LOCAL;
+const                          return T_CONST;
+var                            return T_VAR;
 this                           return T_THIS;
-global                         return T_GLOBAL;
 use                            return T_USE;
 apply                          return T_APPLY;
 to                             return T_TO;