]> granicus.if.org Git - icinga2/commitdiff
Fix location info for strings
authorGunnar Beutner <gunnar@beutner.name>
Tue, 16 Dec 2014 05:18:39 +0000 (06:18 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 16 Dec 2014 05:18:39 +0000 (06:18 +0100)
fixes #8081

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

index 068f5ef2a4951cf160d1980dd3c1f399d156264d..a46ae9f328e066c14a9bdc316fe495cf5cb8d810 100644 (file)
@@ -57,11 +57,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 +79,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}           {
@@ -80,7 +90,7 @@ do {                                                  \
 
        if (result > 0xff) {
                /* error, constant is out-of-bounds */
-               BOOST_THROW_EXCEPTION(ScriptError("Constant is out of bounds: " + String(yytext), *yylloc));
+               BOOST_THROW_EXCEPTION(ScriptError("Constant is out of bounds: " + String(yytext), DebugInfoRange(yyextra->m_LocationBegin, *yylloc)));
        }
 
        yyextra->m_LexBuffer << static_cast<char>(result);
@@ -90,7 +100,7 @@ do {                                                 \
        /* generate error - bad escape sequence; something
         * like '\48' or '\0777777'
         */
-       BOOST_THROW_EXCEPTION(ScriptError("Bad escape sequence found: " + String(yytext), *yylloc));
+       BOOST_THROW_EXCEPTION(ScriptError("Bad escape sequence found: " + String(yytext), DebugInfoRange(yyextra->m_LocationBegin, *yylloc)));
                                }
 
 <STRING>\\n                    { yyextra->m_LexBuffer << "\n"; }
@@ -107,13 +117,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(); BEGIN(HEREDOC); }
+\{\{\{                         {
+       yyextra->m_LexBuffer.str("");
+       yyextra->m_LexBuffer.clear();
+
+       yyextra->m_LocationBegin = *yylloc;
+
+       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());
 
index eb8a046d30167c96b198ca75814c958adf81adcd..38dc2b22c8c0282a9079445bedda2a5cdae5f04b 100644 (file)
@@ -215,7 +215,7 @@ static void MakeRBinaryOp(Expression** result, Expression *left, Expression *rig
 %left T_SHIFT_LEFT T_SHIFT_RIGHT
 %left T_PLUS T_MINUS
 %left T_MULTIPLY T_DIVIDE_OP
-%left UNARY_MINUS
+%left UNARY_MINUS UNARY_PLUS
 %right '!' '~'
 %left '.' '(' '['
 %left T_VAR T_THIS
@@ -756,6 +756,10 @@ rterm: T_STRING
        {
                $$ = new NegateExpression($2, DebugInfoRange(@1, @2));
        }
+       | T_PLUS rterm %prec UNARY_PLUS
+       {
+               $$ = $2;
+       }
        | T_MINUS rterm %prec UNARY_MINUS
        {
                $$ = new SubtractExpression(MakeLiteral(0), $2, DebugInfoRange(@1, @2));
index 6e2eb5dd618ea924e609b09a5d4d2635798bc948..84e2828c1c4ba289a456298bc07dde7845033726 100644 (file)
@@ -115,6 +115,7 @@ public:
 
        int m_IgnoreNewlines;
        std::ostringstream m_LexBuffer;
+       CompilerDebugInfo m_LocationBegin;
 
        std::stack<TypeRuleList::Ptr> m_RuleLists;
        ConfigType::Ptr m_Type;
@@ -127,8 +128,6 @@ public:
        std::stack<String> m_FKVar;
        std::stack<String> m_FVVar;
        std::stack<Expression *> m_FTerm;
-
-
 };
 
 class I2_CONFIG_API ConfigFragmentRegistry : public Registry<ConfigFragmentRegistry, String>