Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/corelibs/typechain/tclexer.hh

Go to the documentation of this file.
00001 /** @file tclexer.h Defines TypechainLexer class.
00002     @author Reed Hedges <reed@zerohour.net>
00003 
00004     Copyright (C) 2002 Reed Hedges
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Lesser General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public
00017     License along with this library; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00019 */
00020 
00021 #ifndef _TCLEXER_HH_
00022 #define _TCLEXER_HH_
00023 
00024 #include <stdio.h>
00025 #include <string>
00026 #include <map>
00027 #include <iostream>
00028 
00029 #ifdef USE_STRSTREAM
00030 #include <strstream>
00031 #else
00032 #include <sstream>
00033 #endif
00034 
00035 using namespace std;
00036 
00037 #ifndef yyFlexLexer
00038 #define yyFlexLexer tcFlexLexer
00039 #include <FlexLexer.h>
00040 #endif
00041 
00042 /**
00043     This class is a yyFlexLexer subclass
00044     with two pure virtual methods you can override to process
00045     identifiers and final types:
00046 
00047         void complete_token(string token, map<string,string> params);
00048 
00049     This method is called whenever a complete identifier token has
00050     been parsed, with parameters (which will have no contents if there
00051     were no parameters. If a key was supplied with no value, the key
00052     will be present with an empty string for value. If an empty identifier
00053     was given (e.g. "foo;;bar;baz") then this method will be called with
00054     an empty string for token (you may then issue an error, warning, or
00055     simply ignore it, as you wish).  Reserved identifiers (such as "type")
00056     are also passed to this method.
00057 
00058         void final_type(string token, map<string,string> params);
00059 
00060     This method is called once for the final media type identifer
00061     token has been parsed, with parameters, analagous to complete_token.
00062 
00063 
00064 */
00065 
00066 class TypechainLexer : public yyFlexLexer {
00067 
00068 protected:
00069     string token;
00070     map<string, string> params;
00071     char *lastkey;
00072     string typestring;
00073 
00074     inline void clear_vars() {
00075         params.clear();
00076         token = "";
00077         if (lastkey != 0) free(lastkey);
00078         lastkey = 0;
00079     }
00080 
00081 public:
00082 
00083     /** Constructor.
00084         @param typestring   The type string.
00085     */
00086     TypechainLexer(const string& typestr) : yyFlexLexer(), lastkey(0) {
00087         typestring = typestr;
00088         switch_streams(
00089 #ifdef USE_STRSTREAM
00090                 new istrstream(typestring.c_str(), typestring.length())
00091 #else
00092                 new istringstream(typestring)
00093 #endif
00094         , 0);
00095     }
00096 
00097 
00098     /** Override this in your subclass to take action on a token. */
00099     virtual void complete_token(string token, map<string, string> params) = 0;
00100 
00101     /** Override this in your subclass to take action on the final type token. */
00102     virtual void final_type(string token, map<string, string> params) = 0;
00103 
00104     /** Call this to do the scan */
00105     int yylex() ;
00106 };
00107 
00108 #endif

Generated on Tue Aug 12 03:55:38 2003 for Interreality Project - VOS by doxygen 1.3.2