Commit 5230ce30 authored by hrchilds's avatar hrchilds
Browse files

Update from July 28, 2003

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@44 18c085ea-50e0-402c-830e-de6fd14e8384
parent 586bda28
......@@ -9,9 +9,12 @@
#include <Colors.h>
#include <ExprGrammar.h>
#include <ParseException.h>
#include <ViewerMessaging.h>
#include <vector>
using std::vector;
ExprParser::ErrorMessageTarget ExprParser::errorMessageTarget = EMT_VIEWER;
class DummyNode : public ExprGrammarNode
{
public:
......@@ -61,6 +64,10 @@ ExprParser::ExprParser() : ParserBase()
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Jeremy Meredith, Mon Jul 28 16:03:49 PDT 2003
// Added more info to the error message in the TimeSpec.
//
// ****************************************************************************
ExprGrammarNode*
ExprParser::ApplyRule(const Symbol &sym, const Rule *rule,
......@@ -334,7 +341,8 @@ ExprParser::ApplyRule(const Symbol &sym, const Rule *rule,
{
const string & id = static_cast<Identifier *>(E[3])->GetVal();
if (id.length() != 1)
throw SyntacticException(E[3]->GetPos());
throw SyntacticException(E[3]->GetPos(),
"needs to be 'i', 'c', or 't'");
char c = id[0];
TimeExpr::Type t;
if (c == 'c' || c == 'C')
......@@ -344,7 +352,8 @@ ExprParser::ApplyRule(const Symbol &sym, const Rule *rule,
else if (c == 'i' || c == 'I')
t = TimeExpr::Index;
else
throw SyntacticException(E[3]->GetPos());
throw SyntacticException(E[3]->GetPos(),
"needs to be 'i', 'c', or 't'");
node = new TimeExpr(p, static_cast<ListExpr *>(E[1]), t);
break;
}
......@@ -374,6 +383,12 @@ ExprParser::ApplyRule(const Symbol &sym, const Rule *rule,
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Jeremy Meredith, Mon Jul 28 16:13:35 PDT 2003
// Made it report normal parse errors through the viewer window
// mechanism if needed. Unhandled reductions will only occur during
// debugging and can still go to cerr.
//
// ****************************************************************************
ExprNode*
ExprParser::Parse(const std::string &s)
......@@ -398,6 +413,7 @@ ExprParser::Parse(const std::string &s)
}
catch (UnhandledReductionException &e)
{
// This should only occur during debugging; print to cerr anyway
cerr << e.Message() << endl;
cerr << "Rule = " << *(e.GetRule()) << endl;
e.GetPos().PrintText(cerr, text);
......@@ -405,8 +421,15 @@ ExprParser::Parse(const std::string &s)
}
catch (ParseException &e)
{
cerr << e.Message() << endl;
e.GetPos().PrintText(cerr, text);
char error[1024];
SNPRINTF(error, 1024, "%s\n%s",
e.Message(), e.GetPos().GetText(text).c_str());
if (errorMessageTarget == EMT_VIEWER)
Error(error);
else if (errorMessageTarget == EMT_CONSOLE)
cerr << error;
return NULL;
}
......
......@@ -20,6 +20,10 @@
// Brad Whitlock, Fri Jun 28 15:20:36 PST 2002
// Changed the name of the base class.
//
// Jeremy Meredith, Mon Jul 28 16:54:47 PDT 2003
// Add the ability to set the error reporting message target to
// the console, the viewer error message mechanism, or neither.
//
// ****************************************************************************
class VIEWER_API ExprParser : private ParserBase
......@@ -28,12 +32,24 @@ class VIEWER_API ExprParser : private ParserBase
ExprParser();
ExprNode *Parse(const std::string &);
enum ErrorMessageTarget
{
EMT_NONE,
EMT_CONSOLE,
EMT_VIEWER
};
static void SetErrorMessageTarget(const ErrorMessageTarget emt)
{
errorMessageTarget = emt;
}
protected:
ExprGrammarNode *ApplyRule(const Symbol&, const Rule*,
std::vector<ExprGrammarNode*>&, Pos);
private:
Scanner scanner;
static ErrorMessageTarget errorMessageTarget;
};
#endif
......@@ -38,6 +38,9 @@
# Jeremy Meredith, Fri Jul 12 14:30:11 PDT 2002
# Unified include directories.
#
# Jeremy Meredith, Mon Jul 28 16:56:09 PDT 2003
# Changed some libraries for linking the standalone debugging parser.
#
##############################################################################
##
......@@ -57,8 +60,8 @@ VTK_INCLUDE=@VTK_INCLUDES@
LIBS=-L../../lib -L../../vtkqt -lengineproxy -lenginerpc -lviewerrpc \
-lmdserverproxy -lmdserverrpc -ldbatts -lparser -lplugin -lviswindow \
-lavtmath_ser -lplotter -lpipeline_ser -lvisit_vtk -lvtkqt -lwinutil \
@QT_LIBS@ -lmisc -lcomm -lrpc -lstate -lutility -lavtexceptions \
-lviewer $(VTK_LIBS) $(X_LIBS) @LIBS@ @PTHREAD_LIB@
@QT_LIBS@ -lmisc -lcomm -lvclproxy -lvclrpc -lproxybase -lstate -lutility \
-lavtexceptions -lviewer $(VTK_LIBS) $(X_LIBS) @LIBS@ @PTHREAD_LIB@
LDFLAGS=@LDFLAGS@ @QT_LDFLAGS@
CXXFLAGS=@CXXFLAGS@
CPPFLAGS=@CPPFLAGS@ ${VTK_INCLUDE} -I. -I../../include/visit
......
......@@ -2,6 +2,7 @@
#define PARSEEXEPTION_H
#include "Pos.h"
#include <snprintf.h>
class Rule;
// ****************************************************************************
......@@ -13,6 +14,10 @@ class Rule;
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Jeremy Meredith, Mon Jul 28 16:57:42 PDT 2003
// Added a little extra info to the syntax error messages.
//
// ****************************************************************************
class ParseException
{
......@@ -34,8 +39,13 @@ class LexicalException : public ParseException
class SyntacticException : public ParseException
{
public:
SyntacticException(Pos p) : ParseException(p) { }
virtual const char *Message() { return "Parse error -- unexpected token:"; }
SyntacticException(Pos p, const std::string &s) : ParseException(p)
{
SNPRINTF(msg, 1024, "Parse error -- unexpected token (%s):", s.c_str());
}
virtual const char *Message() { return msg; }
private:
char msg[1024];
};
class UnexpectedEndException : public ParseException
......
......@@ -160,6 +160,10 @@ ParserBase::PrintState(ostream &o)
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Jeremy Meredith, Mon Jul 28 16:57:00 PDT 2003
// Added extra info to the error message.
//
// ****************************************************************************
void
ParserBase::ParseOneToken(Token *t)
......@@ -184,6 +188,7 @@ ParserBase::ParseOneToken(Token *t)
if (t->GetType() == TT_EOF)
throw UnexpectedEndException(t->GetPos());
else
throw SyntacticException(t->GetPos());
throw SyntacticException(t->GetPos(),
GetTokenString(t->GetType()));
}
}
......@@ -14,6 +14,10 @@
// Programmer: Jeremy Meredith
// Creation: April 4, 2002
//
// Modifications:
// Jeremy Meredith, Mon Jul 28 16:59:51 PDT 2003
// Added the GetText method.
//
// ****************************************************************************
struct VIEWER_PARSER_API Pos
......@@ -44,6 +48,17 @@ struct VIEWER_PARSER_API Pos
o << '^';
o << endl;
}
std::string GetText(const std::string &s) const
{
int i;
std::string msg = s + '\n';
for (i=0; i<p1; i++)
msg += ' ';
for (i=p1; i<=p2; i++)
msg += '^';
msg += '\n';
return msg;
}
};
#endif
......@@ -9,13 +9,22 @@ using std::deque;
#include "Token.h"
#include "ParseException.h"
// ----------------------------------------------------------------------------
// Scanner modifications:
// Jeremy Meredith, Mon Jul 28 14:36:21 PDT 2003
// Allow dots in tokens that started with were clearly scanned as
// identifiers already. For example, "alpha.1" will scan as a single
// identifier now, without the need for the "<>" notation.
//
// ----------------------------------------------------------------------------
static const int StateTransition[13][8] = {
// Quo Sgn Sym Eee Alp Dig Dot Spc
/* 0*/ { 1, 3, 3, 4, 4, 5, 6, 12 },
/* 1*/ { 2, 1, 1, 1, 1, 1, 1, 1 },
/* 2*/ { -1, -1, -1, -1, -1, -1, -1, -1 },
/* 3*/ { -1, -1, -1, -1, -1, -1, -1, -1 },
/* 4*/ { -1, -1, -1, 4, 4, 4, -1, -1 },
/* 4*/ { -1, -1, -1, 4, 4, 4, 4, -1 },
/* 5*/ { -1, -1, -1, 11, 4, 5, 7, -1 },
/* 6*/ { -1, -1, -1, -1, -1, 7, -1, -1 },
/* 7*/ { -1, -1, -1, 8, -1, 7, -1, -1 },
......
......@@ -8,6 +8,12 @@
// Programmer: Jeremy Meredith
// Creation: April 5, 2002
//
// Modifications:
// Jeremy Meredith, Mon Jul 28 16:53:15 PDT 2003
// Made the expression parser print error messages to the console.
// (Another simultaneous change made the default be the viewer error
// reporting mechanism.)
//
// ****************************************************************************
int
main(int argc, char *argv[])
......@@ -15,6 +21,7 @@ main(int argc, char *argv[])
if (argc<2) {cerr<<"needs an argument\n"; exit(-1);}
ExprParser parser;
ExprParser::SetErrorMessageTarget(ExprParser::EMT_CONSOLE);
for (int i=1; i<argc; i++)
{
......
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