00001 /* 00002 * File: macro_expander.cc 00003 * $Id: macro_token_expander.cc,v 1.2 2002/05/07 10:02:18 alec Exp $ 00004 * 00005 * Author: Alec Panoviciu (alecu@email.com) 00006 * 00007 * Comments: 00008 * 00009 * Revision history: 00010 * 00011 * $Log: macro_token_expander.cc,v $ 00012 * Revision 1.2 2002/05/07 10:02:18 alec 00013 * fixed some bugs & mem leaks; added MORE tokens support 00014 * 00015 * Revision 1.1 2002/04/29 17:57:35 alec 00016 * *** empty log message *** 00017 * 00018 */ 00019 00020 /* 00021 Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com) 00022 00023 This program is free software; you can redistribute it and/or modify 00024 it under the terms of the GNU General Public License as published by 00025 the Free Software Foundation; either version 2 of the License, or 00026 (at your option) any later version. 00027 00028 This program is distributed in the hope that it will be useful, 00029 but WITHOUT ANY WARRANTY; without even the implied warranty of 00030 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00031 GNU General Public License for more details. 00032 00033 You should have received a copy of the GNU General Public License 00034 along with this program; if not, write to the Free Software 00035 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00036 00037 */ 00038 00039 00040 #include "macro_token_expander.hh" 00041 #include "re_node.hh" 00042 00043 void MacroTokenExpander::addMacro (const string &name, 00044 ReNode *regexp, const Position &pos) 00045 { 00046 if (macros.find(name) != macros.end()) 00047 cerr << formatWarning(pos, string("Macro token \"" + name + "\" redefined")) 00048 << endl 00049 << formatWarning(macros[name].pos, string(" Previous definition of \"") 00050 + name + "\"") << endl; 00051 00052 macros[name] = MacroDef(regexp, pos); 00053 } 00054 00055 ReNode* MacroTokenExpander::getMacro (const string &name) throw (ParseException) 00056 { 00057 if (macros.find(name) == macros.end()) 00058 throw ParseException(string("Macro token \"") + name + "\" not defined."); 00059 00060 return macros[name].regexp->clone(); 00061 }