ustyleparser.hpp

00001 /* ==================================================== ======== ======= *
00002 *
00003 *  ustyleparser.hpp
00004 *  Ubit Project
00005 *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00006 *  (C) 1999-2006 EricLecolinet / ENST Paris / http://www.enst.fr/~elc/ubit
00007 *
00008 * ***********************************************************************
00009 * COPYRIGHT NOTICE :
00010 * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
00011 * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00012 * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
00013 * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
00014 * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00015 * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00016 * ***********************************************************************
00017 * ==================================================== [(c)Elc] ======= *
00018 * ==================================================== ======== ======= */
00019 
00020 #ifndef _ustyleparser_hpp_
00021 #define _ustyleparser_hpp_
00022 //pragma ident  "@(#)ustyleparser.hpp   ubit:05.05.00"
00023 #include <vector> 
00024 #include <fstream>
00025 #include <ubit/ubrick.hpp>
00026 #include <ubit/ustr.hpp>
00027 namespace ubit {
00028 
00029 /* ==================================================== ======== ======= */
00034 class UStyleParser {
00035 public:
00036 
00037   struct StyleMaker {
00038     std::vector<UStr*> selectors;
00039     unsigned int count;
00040 
00041     StyleMaker();
00042     virtual ~StyleMaker();
00043     virtual void begin() {}
00044     virtual void create() {}
00045     virtual void addProp(const UStr& name, const UStr& value) {}
00046     virtual void end(bool ok) {}
00047   };
00048 
00049   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00050 
00051   UStyleParser();
00052   virtual ~UStyleParser();
00053 
00054   virtual int parseImpl(StyleMaker&, const UStr& buffer);
00056 
00057   int getStatus() {return stat;}
00059 
00060   void setErrorOutput(std::ostream&);
00061   void setErrorOutput(UStr*);
00062   
00063 protected:
00064   bool readStyleDef(StyleMaker&);
00066 
00067   bool readStyleSelectors(StyleMaker&);
00069 
00070   bool readStyleProps(StyleMaker&);
00072   
00073   void skipSpaces();
00074   bool readName(UStr& name);
00075   bool readValue(UStr& value);
00076   bool readNameValuePair(UStr& name, UStr& value);
00077   
00078   virtual void error(const char* msg, const UChar* line);
00079   virtual void error(const char* msg_start, const UStr& name,
00080                      const char* msg_end, const UChar* line);
00081   virtual void unexpected(const char* msg, const UChar* line);
00082   
00083   bool permissive;
00084   int stat;
00085   const UChar *text_buffer, *p;
00086   uptr<UStr> sout;
00087   std::ostream* fout;
00088 
00089 public:
00090   static void error(std::ostream* fout, UStr* sout, const char* errtype,
00091                     const UChar *text_buffer,
00092                     const char* msg_start, const UStr& name,
00093                     const char* msg_end, const UChar* line);
00094 };
00095 }
00096 #endif
00097 /* ==================================================== [TheEnd] ======= */
00098 /* ==================================================== [(c)Elc] ======= */
00099 

Generated on Mon Jan 29 00:20:40 2007 for Ubit by  doxygen 1.4.7