File indexing completed on 2024-04-28 15:35:14

0001 /***************************************************************************
0002  *   Copyright (C) 2004 by Tomas Mecir                                     *
0003  *   kmuddy@kmuddy.org                                                     *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU Library General Public License as       *
0007  *   published by the Free Software Foundation; either version 2 of the    *
0008  *   License, or (at your option) any later version.                       *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU Library General Public License for more details.                  *
0014  ***************************************************************************/
0015 #ifndef CMXPPARSER_H
0016 #define CMXPPARSER_H
0017 
0018 #include <list>
0019 #include <string>
0020 
0021 using namespace std;
0022 
0023 /**
0024 First-stage parser, it looks for newlines, elements and line tags.
0025 
0026 @author Tomas Mecir
0027 */
0028 
0029 enum chunkType {
0030   chunkNone = 0,
0031   chunkText,
0032   chunkTag,
0033   chunkError
0034 };
0035 
0036 enum parserState {
0037   pText = 0,
0038   pAnsiSeq,
0039   pTag,
0040   pComment,
0041   pQuotedParam
0042 };
0043 
0044 struct chunk {
0045   chunkType chk;
0046   string text;
0047 };
0048 
0049 class cMXPState;
0050 class cElementManager;
0051 class cResultHandler;
0052 
0053 class cMXPParser {
0054 public:
0055   /** constructor */
0056   cMXPParser (cMXPState *st = 0, cElementManager *elm = 0, cResultHandler *res = 0);
0057   /** destructor */
0058   ~cMXPParser ();
0059 
0060   void reset ();
0061     
0062   /** parse text and send chunks to the correct classes for further processing */
0063   void parse (const string &text);
0064   
0065   /** simple parser - only recognizes text and tags - used to parse !ELEMENT tag */
0066   void simpleParse (const string &text);
0067   /** do we have more things to report? used after simpleParse() */
0068   bool hasNext ();
0069   /** next chunk; used in conjunction with simpleParse() */
0070   chunk getNext ();
0071   
0072 protected:
0073   cMXPState *state;
0074   cElementManager *elements;
0075   cResultHandler *results;
0076   
0077   string str;
0078   parserState pstate;
0079   list<chunk> chunks;
0080   char quoteChar;
0081   bool wasBackslashR;
0082 };
0083 
0084 #endif