Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

sreader.hpp

Go to the documentation of this file.
00001 // +-------------------------------------------------------------------------+
00002 // |               I__n__t__e__L__i__b           0.6.10 development          |
00003 // | Copyright (c) Andrey Vikt. Stolyarov <crocodil_AT_croco.net> 2000-2007. |
00004 // |                                                                         |
00005 // | This is free software. The library part is available under              |
00006 // |                               GNU LESSER GENERAL PUBLIC LICENSE v.2.1.  |
00007 // | GNU LGPL v2.1 is found in docs/gnu_gpl2.txt,  or at  http://www.gnu.org |
00008 // |     Please see also docs/readme.txt and visit http://www.intelib.org    |
00009 // |                                                                         |
00010 // | !!! THERE IS NO WARRANTY OF ANY KIND, NEITHER EXPRESSED NOR IMPLIED !!! |
00011 // +-------------------------------------------------------------------------+
00012 
00013 
00014 
00015 
00025 #ifndef INTELIB_SREADER_HPP_SENTRY
00026 #define INTELIB_SREADER_HPP_SENTRY
00027 
00028 #include "../sexpress/sexpress.hpp"
00029 #include "../sexpress/sstring.hpp"
00030 #include "../sexpress/squeue.hpp"
00031 #include "sstream.hpp"
00032 
00034 
00038 class IntelibPackage {
00039 public:
00041     virtual ~IntelibPackage() {}
00043 
00046     virtual SReference MakeSymbol(const char *name) = 0;
00047 };
00048 
00050 
00055 class IntelibDummyPackage : public IntelibPackage {
00056 public:
00057     IntelibDummyPackage() {}
00059     virtual SReference MakeSymbol(const char *name);
00060 };
00061 
00062 extern IntelibDummyPackage TheDummyPackage;
00063 
00064 
00066 
00082 class IntelibGenericReader {
00083 public:
00085     typedef SReference (*process_function)(const SReference&);
00086 private:
00087     class IntelibSLexAnalyser *lexer;
00088     struct SpecialLexic {
00089         SString id; 
00090         enum sl_type { quoter, sequence, seq_closer, cons_sign } t;
00091             /* for quoter, process is given the expression which follows
00092                  the quoter lexem 
00093                for sequence, process is given the list of members of the
00094                  sequence
00095                for seq_closer and cons_sign, process is ignored (should be 0)
00096              */
00097         process_function process;
00098         SReference the_closer; 
00100         SReference the_cons_sign; 
00102         SpecialLexic *next;
00103     } *first_sl;
00104     SpecialLexic* AddSpecialLexic(const char *str,
00105                                   SpecialLexic::sl_type t,
00106                                   process_function proc);
00107 
00108     IntelibPackage *the_package;
00109     bool uppercase;
00110 
00111     SQueue parts;
00112     SQueue ready;
00113     int unclosed_brackets;
00114     SString file_name;
00115 public:
00117     IntelibGenericReader();
00119     ~IntelibGenericReader();
00120 
00122     void AddDelimiter(const char *str, const SReference &tok);
00123 
00125     void AddToken(const char *str, const SReference &tok);
00126 
00128     void AddTokenType(const char *str, SReference (*fun)(const char*));
00129 
00131     void AddStringLiteral(const char *str, int closing_char,
00132                           SReference (*fun)(const char*) = 0);
00133 
00135     void AddQuoter(const char *str, process_function proc);
00136 
00138     void AddSequenceOpener(const char *str,
00139                            process_function proc,
00140                            const char *closer,
00141                            const char *cons_sign = 0,
00142                            bool cons_sign_delimiter = false);
00143 
00145     void AddTailSeparator(const char *str, bool is_delimiter = false);
00146 
00148 
00151     void AddComment(const char *starter, const char *closer = "\n");
00152 
00154 
00158     IntelibPackage* SetPackage(IntelibPackage *a_package)
00159     {
00160         IntelibPackage *old = the_package;
00161         the_package = a_package;
00162         return old;
00163     } 
00164 
00166     void SetUppercase(bool u) { uppercase = u; }
00167 
00169 
00172     void SetLine(int l, const SString &afn = "");
00174     int GetLine() const;
00176     const SString& GetFileName() const { return file_name; }
00177 
00179     void FeedChar(int c);
00181     void FeedString(const char *s);
00183     void FeedEof() { FeedChar(-1); }
00184 
00186 
00193     bool IsEmpty() const { return parts.IsEmpty() && ready.IsEmpty(); }
00195     bool IsReady() const { return !ready.IsEmpty(); }
00196 
00198 
00203     SReference Get();
00205 
00209     void Drop();
00210 
00212 
00222     SReference Read(const SStreamRef& stream);
00223 
00225 
00228     static SLabel& EofMarker;
00229 
00230 private:
00231     void HandleLexema(const SReference &lexpair); // lexpair is (lex . line)
00232     void HandleSpecialLex(SpecialLexic *sp, int line);
00233     SReference DoMakeSymbol(const char *s) const;
00234     void HandleEof();
00235     void FinishParts();
00236     SReference DoFinishParts();
00237     SReference DoFinishPartsSeq(const SReference& closer,
00238                                 const SReference& conser,
00239                                 int begline);
00240 };
00241 
00243 
00252 class IntelibReader : public IntelibGenericReader {
00253 public:
00254     IntelibReader();
00255 };
00256 
00257 
00259 class IntelibX_reader_error : public IntelibX {
00260     int line, beg_line;
00261     SString fname;
00262 public:
00264 
00274     IntelibX_reader_error(SReference a_param,
00275                           int a_line,
00276                           int a_begline = -1,
00277                           const SString &afn = "");
00278     int Line() const { return line; }
00279     int ExpBegLine() const { return beg_line; }
00280     const SString& FileName() const { return fname; }
00281 };
00282 
00284 
00287 class IntelibX_reader_not_ready : public IntelibX {
00288 public:
00289     IntelibX_reader_not_ready();
00290 };
00291 
00293 
00296 class IntelibX_read_eof : public IntelibX {
00297 public:
00298     IntelibX_read_eof(SReference a_param);
00299 };
00300 
00301 
00303 
00313 extern IntelibGenericReader *PTheIntelibReader;
00314 
00315 
00317 
00321 void add_vectors_to_reader(class IntelibReader &reader);
00322 
00324 
00328 void add_hashtables_to_reader(class IntelibReader &reader);
00329 
00330 #endif // sentry

Generated on Tue Dec 18 00:39:46 2007 for InteLib by  doxygen 1.4.1