filters
ailexer.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef AILEXER_H
00021 #define AILEXER_H
00022
00023 #include <qiodevice.h>
00024 #include <qstring.h>
00025
00029 typedef enum {
00030 State_Comment=0,
00031 State_Integer,
00032 State_Float,
00033 State_String,
00034 State_Token,
00035 State_Reference,
00036 State_Start,
00037 State_BlockStart,
00038 State_BlockEnd,
00039 State_ArrayStart,
00040 State_ArrayEnd,
00041 State_Byte,
00042 State_ByteArray,
00043 State_StringEncodedChar,
00044 State_CommentEncodedChar,
00045 State_ByteArray2
00046 } State;
00047
00048 typedef enum {
00049 Action_Copy=1,
00050 Action_CopyOutput,
00051 Action_Output,
00052 Action_Ignore,
00053 Action_Abort,
00054 Action_OutputUnget,
00055 Action_InitTemp,
00056 Action_CopyTemp,
00057 Action_DecodeUnget,
00058 Action_ByteArraySpecial
00059 } Action;
00060
00061 class StringBuffer {
00062 public:
00063 StringBuffer ();
00064 virtual ~StringBuffer ();
00065
00066 void append (char c);
00067 void clear();
00068 QString toString() const;
00069 uint length();
00070 double toFloat();
00071 int toInt();
00072 const char *latin1();
00073 QString mid( uint index, uint len=0xffffffff) const;
00074 private:
00075 char *m_buffer;
00076 uint m_length;
00077 int m_capacity;
00078
00079 void ensureCapacity (int p_capacity);
00080 };
00081
00082 class AILexer {
00083 public:
00084 AILexer();
00085 virtual ~AILexer();
00086
00087 virtual bool parse (QIODevice& fin);
00088 private:
00089 State m_curState;
00090 StringBuffer m_buffer;
00091 StringBuffer m_temp;
00092
00093
00094
00095
00096 void nextStep (char c, State* newState, Action* newAction);
00097
00098 void doOutput ();
00099 void doHandleByteArray ();
00100 uchar getByte();
00101 uchar decode();
00102
00103 protected:
00104 virtual void parsingStarted();
00105 virtual void parsingFinished();
00106 virtual void parsingAborted();
00107
00108 virtual void gotComment (const char *value);
00109 virtual void gotIntValue (int value);
00110 virtual void gotDoubleValue (double value);
00111 virtual void gotStringValue (const char *value);
00112 virtual void gotToken (const char *value);
00113 virtual void gotReference (const char *value);
00114 virtual void gotBlockStart ();
00115 virtual void gotBlockEnd ();
00116 virtual void gotArrayStart ();
00117 virtual void gotArrayEnd ();
00118 virtual void gotByte (uchar value);
00119 virtual void gotByteArray (const QByteArray &data);
00120 };
00121
00122 #endif
00123
|