Fix location info for strings

fixes #8081
This commit is contained in:
Gunnar Beutner 2014-12-16 06:18:39 +01:00
parent d72bd4fec2
commit 8ef8316ca6
3 changed files with 34 additions and 9 deletions

View 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());

View 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));

View 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>