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
00095 ASCString typeName;
00096
00097 int evalID();
00098
00099 void buildInheritance( TextPropertyList& tpl );
00100 void resolveAllAlias( );
00101 bool isAbstract() { return abstract; };
00102 void print( int indent = 0 );
00103 };
00104
00105
00107 class TextFormatParser {
00108 tnstream *stream;
00109 typedef list<ASCString> Level;
00110 Level level;
00111 ASCString s1, s2, s3;
00112 int levelDepth;
00113 ASCString primaryName;
00114
00115 TextPropertyGroup* textPropertyGroup;
00116
00117 public:
00118 TextFormatParser( tnstream* stream_, const ASCString& primaryName_ = "" ) : stream ( stream_ ), levelDepth ( 0 ), primaryName ( primaryName_ ), textPropertyGroup ( NULL ) {};
00119 TextPropertyGroup* run ( );
00120 ASCString readLine ( );
00121
00122 static const int operationsNum;
00123 static const char* operations[];
00124 static const char* whiteSpace;
00125
00126 protected:
00127 void startLevel ( const ASCString& levelName );
00128 void parseLine ( const ASCString& line );
00129 void error ( const ASCString& errmsg );
00130 };
00131
00132
00133 #endif