Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

parse_util.cc

Go to the documentation of this file.
00001 /*
00002  *  File:       parse_util.cc
00003  *              $Id: parse_util.cc,v 1.3 2002/04/29 09:34:10 alec Exp $
00004  *
00005  *  Author:     Alec Panoviciu (alecu@email.com)
00006  *
00007  *  Comments:
00008  *
00009  *  Revision history:
00010  *
00011  *  $Log: parse_util.cc,v $
00012  *  Revision 1.3  2002/04/29 09:34:10  alec
00013  *  scanner ptree building compiles
00014  *
00015  */
00016 
00017 /* 
00018   Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com)
00019 
00020   This program is free software; you can redistribute it and/or modify
00021   it under the terms of the GNU General Public License as published by
00022   the Free Software Foundation; either version 2 of the License, or
00023   (at your option) any later version.
00024 
00025   This program is distributed in the hope that it will be useful,
00026   but WITHOUT ANY WARRANTY; without even the implied warranty of
00027   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00028   GNU General Public License for more details.
00029 
00030   You should have received a copy of the GNU General Public License
00031   along with this program; if not, write to the Free Software
00032   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00033 
00034  */
00035 
00036 
00037 #include "parse_util.hh"
00038 #include <sstream>
00039 
00040 string fileName = "";
00041 
00042 string formatError (const Position& pos, const string &message)
00043 {
00044   ostringstream ss;
00045   if (pos.ln) {
00046     if (fileName != "") ss << " " << fileName << ":";
00047     else ss << " ";
00048     ss << pos.ln << ":";
00049     if (pos.col) ss << pos.col << ":";
00050   }
00051   ss << " " << message;
00052   return ss.str();
00053 }
00054 
00055 
00056 string formatError (const string &message)
00057 {
00058   return formatError(Position(), message);
00059 }
00060 
00061 string formatError (const ParseException &ex)
00062 {
00063   return formatError(ex.where(), ex.what());
00064 }
00065 
00066 string formatWarning (const Position& pos, const string &message)
00067 {
00068   ostringstream ss;
00069   ss << "Warning:";
00070   if (pos.ln) {
00071     if (fileName != "") ss << " " << fileName << ":";
00072     else ss << " ";
00073     ss << pos.ln << ":";
00074     if (pos.col) ss << pos.col << ":";
00075   }
00076   ss << " " << message;
00077   return ss.str();
00078 }
00079 
00080 
00081 string formatWarning (const string &message)
00082 {
00083   return formatWarning(Position(), message);
00084 }
00085 
00086 
00087 void die (const string &message)
00088 {
00089   cerr << message << endl;
00090   cerr.flush();
00091   exit(1);
00092 }

Generated at Tue Jul 9 21:05:44 2002 for CppCC by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001