00001
00002
00003
00004
00005
00006
00007
00008
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef textfileparserH
00024 #define textfileparserH
00025
00026 #include <vector>
00027 #include <map>
00028 #include "basictypes.h"
00029 #include "ascstring.h"
00030 #include "errors.h"
00031 #include "basestreaminterface.h"
00032
00033
00034 class ParsingError : public ASCmsgException {
00035 public:
00036 ParsingError ( const ASCString& msg ) : ASCmsgException ( msg ) {};
00037 };
00038
00039 class TextPropertyGroup;
00040
00041 class TextPropertyList : public PointerList<TextPropertyGroup*> {
00042 typedef map<int,TextPropertyGroup*> IdentCache;
00043 IdentCache identCache;
00044 public:
00045 void buildIDs();
00046 TextPropertyGroup* get ( int id );
00047 };
00048
00052 class TextPropertyGroup {
00053 bool inheritanceBuild;
00054 bool abstract;
00055 int id;
00056 public:
00057 TextPropertyGroup() : inheritanceBuild ( false ), abstract ( false ), id ( -1 ) {};
00058
00059 class Entry {
00060 public:
00061 ASCString propertyName;
00062 enum Operator { eq, mult_eq, add_eq, alias, alias_all, sub_eq, alias_all_resolved } op;
00063 ASCString value;
00064 Entry* parent;
00065 Entry ( const ASCString& propertyName_, Operator op_, const ASCString& value_ ) : propertyName ( propertyName_ ), op ( op_ ), value ( value_ ), parent ( NULL ) { propertyName.toLower(); };
00066 ASCString toString() const;
00067 };
00068
00069 private:
00070 typedef map<ASCString, Entry*> EntryCache;
00071 EntryCache entryCache;
00072 typedef list<Entry> Entries;
00073 Entries entries;
00074
00075 typedef list<Entry*> EntryPointerList;
00076
00077 protected:
00078 void error ( const ASCString& msg, bool printInheritance = true );
00079 bool processAlias( Entry& e, Entries& entriesToAdd, EntryPointerList& markAsResolved );
00080 int findGeneration ( Entry* e );
00081 ASCString listInheritanceFilenames();
00082 public:
00083 void addEntry( const Entry& entry );
00084 Entry* find( const ASCString& n );
00085 typedef vector<Entry*> Matches;
00086 void findMatches( const ASCString& name, const ASCString& name_without_dot, Matches& matches );
00087
00088 typedef list<TextPropertyGroup*> Parents;
00089 Parents parents;
00090
00091 ASCString fileName;
00092 ASCString location;
00093 ASCString archive;
00094
00096 ASCString typeName;
00097
00098 int evalID();
00099
00100 void buildInheritance( TextPropertyList& tpl );
00101 void resolveAllAlias( );
00102 bool isAbstract() { return abstract; };
00103 void print( int indent = 0 );
00104 };
00105
00106
00108 class TextFormatParser {
00109 tnstream *stream;
00110 typedef list<ASCString> Level;
00111 Level level;
00112 ASCString s1, s2, s3;
00113 int levelDepth;
00114 ASCString primaryName;
00115
00116 TextPropertyGroup* textPropertyGroup;
00117
00118 public:
00119 TextFormatParser( tnstream* stream_, const ASCString& primaryName_ = "" ) : stream ( stream_ ), levelDepth ( 0 ), primaryName ( primaryName_ ), textPropertyGroup ( NULL ) {};
00120 TextPropertyGroup* run ( );
00121 ASCString readLine ( );
00122
00123 static const int operationsNum;
00124 static const char* operations[];
00125 static const char* whiteSpace;
00126
00127 protected:
00128 void startLevel ( const ASCString& levelName );
00129 void parseLine ( const ASCString& line );
00130 void error ( const ASCString& errmsg );
00131 };
00132
00133
00134 #endif