uxmlparser.hpp

00001 /* ==================================================== ======== ======= *
00002 *
00003 *  uxmlparser.hpp
00004 *  Ubit Project
00005 *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00006 *  (C) 1999-2005 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 //pragma ident  "@(#)uxmlparser.hpp ubit:05.05.00"
00021 #ifndef _uxmlparser_hpp_
00022 #define _uxmlparser_hpp_
00023 #include <ubit/udom.hpp>
00024 #include <fstream>
00025 namespace ubit {
00026 
00027 class UXmlGrammar;
00028 
00029 /* ==================================================== [Elc] ======= */
00030 /* ==================================================== ===== ======= */
00036 class UXmlParser {
00037 public:
00038   struct ParseError {};
00039 
00040   UXmlParser();
00042   
00043   virtual ~UXmlParser();
00044 
00045   void addGrammar(const UXmlGrammar&);
00051   void setPermissive(bool b) {permissive = b;}
00061   void setCollapseSpaces(bool b) {collapse_spaces = b;}
00067   UXmlDoc* read(const UStr& pathname);
00072   UXmlDoc* parse(const UStr& doc_name, const UStr& doc_text);
00078   int getStatus() {return stat;}
00080   
00081   void setErrorOutput(UStr& error_buffer);
00083 
00084   void setErrorOutput(std::ostream&);
00086 
00087   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00088 
00089 protected:
00090   void readElement(UGroup* parent);
00091   void readText(UGroup* parent);
00092   bool readXMLDeclaration();
00093   void readXMLInstruction(UGroup* parent);
00094   void readSGMLData(UGroup* parent);
00095 
00096   void skipSpaces();
00097   UChar readCharEntityReference();
00098   bool readName(UStr&);
00099   bool readQuotedValue(UStr&, UChar quoting_char);
00100   bool readUnquotedValue(UStr&);
00101   bool readNameValuePair(UStr& name, UStr& value);
00102   UGroup* readElementStartTag(UStr& elem_name, int& stat);
00103   int  readElementEndTag(const UStr& elem_name);
00104 
00105   void error(const char* msg, const UChar* line);
00106   void error(const char* msg_start, const UStr& name,
00107              const char* msg_end, const UChar* line);
00108   void unexpected(const char* msg, const UChar* line);
00109  
00110   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00111 
00112 private:
00113   static const int INVALID_TAG = 0, END_TAG = 1, END_TAG_AND_ELEM = 2;
00114   int stat;
00115   bool permissive, collapse_spaces;
00116   const UChar *text_buffer, *p;
00117   UXmlDoc* doc;
00118   uptr<UStr> sout;
00119   std::ostream* fout;
00120   UXmlGrammars* parser_grammars;
00121 };
00122 }
00123 #endif
00124 /* ==================================================== [(c)Elc] ======= */
00125 /* ==================================================== ======== ======= */
00126 
00127 

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