Commit f7f80c5e authored by miller86's avatar miller86

better handle truncation of error messages from expression parsing

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@10371 18c085ea-50e0-402c-830e-de6fd14e8384
parent 8c050c69
......@@ -588,6 +588,9 @@ ExprParser::ApplyRule(const Symbol &sym,
// Delete the tokens that have not taken part in a rule reduction -- in
// this case that means Space tokens and the final EOF token.
//
// Mark C. Miller, Wed Mar 17 10:03:09 PDT 2010
// Pass buffer length estimate to GetErrorText to handle truncation of
// error messages too long to fit into buffer.
// ****************************************************************************
ParseTreeNode*
ExprParser::Parse(const std::string &s)
......@@ -625,8 +628,9 @@ ExprParser::Parse(const std::string &s)
CATCH2(ParseException, e)
{
char error[1024];
SNPRINTF(error, 1024, "%s\n%s",
e.Message(), e.GetPos().GetErrorText(text).c_str());
int n = (int) sizeof(error) - strlen(e.Message()) - 2;
SNPRINTF(error, sizeof(error), "%s\n%s",
e.Message(), e.GetPos().GetErrorText(text,n).c_str());
if (errorMessageTarget == EMT_COMPONENT)
{
......@@ -647,4 +651,3 @@ ExprParser::Parse(const std::string &s)
return GetParseTree();
}
......@@ -66,6 +66,8 @@
// Jeremy Meredith, Mon Jun 13 12:14:21 PDT 2005
// Let Join() work with null positions.
//
// Mark C. Miller, Wed Mar 17 10:02:23 PDT 2010
// Handle truncation of error text to specified buffer size.
// ****************************************************************************
class PARSER_API Pos
......@@ -95,15 +97,19 @@ class PARSER_API Pos
o << '^';
o << endl;
}
std::string GetErrorText(const std::string &s) const
std::string GetErrorText(const std::string &s, int _n) const
{
int i;
std::string msg = s + '\n';
int n = 0;
std::string tmp, msg;
if (_n <= 2*(p2+1))
n = p2 - (_n/2) + 8; // '8' is fudge
msg = std::string(s,n) + '\n';
for (i=0; i<p1; i++)
msg += ' ';
tmp += ' ';
for (i=p1; i<=p2; i++)
msg += '^';
msg += '\n';
tmp += '^';
msg += (std::string(tmp,n) + '\n');
return msg;
}
std::string GetText(const std::string &s) const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment