filters

ailexer.h
1/* This file is part of the KDE project
2 Copyright (C) 2002, Dirk Schönberger <dirk.schoenberger@sz-online.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef AILEXER_H
21#define AILEXER_H
22
23#include <tqiodevice.h>
24#include <tqstring.h>
25
29typedef enum {
30 State_Comment=0,
31 State_Integer,
32 State_Float,
33 State_String,
34 State_Token,
35 State_Reference,
36 State_Start,
37 State_BlockStart,
38 State_BlockEnd,
39 State_ArrayStart,
40 State_ArrayEnd,
41 State_Byte,
42 State_ByteArray,
43 State_StringEncodedChar,
44 State_CommentEncodedChar,
45 State_ByteArray2
46} State;
47
48typedef enum {
49 Action_Copy=1,
50 Action_CopyOutput,
51 Action_Output,
52 Action_Ignore,
53 Action_Abort,
54 Action_OutputUnget,
55 Action_InitTemp,
56 Action_CopyTemp,
57 Action_DecodeUnget,
58 Action_ByteArraySpecial
59} Action;
60
61class StringBuffer {
62public:
63 StringBuffer ();
64 virtual ~StringBuffer ();
65
66 void append (char c);
67 void clear();
68 TQString toString() const;
69 uint length();
70 double toFloat();
71 int toInt();
72 const char *latin1();
73 TQString mid( uint index, uint len=0xffffffff) const;
74private:
75 char *m_buffer;
76 uint m_length;
77 int m_capacity;
78
79 void ensureCapacity (int p_capacity);
80};
81
82class AILexer {
83public:
84 AILexer();
85 virtual ~AILexer();
86
87 virtual bool parse (TQIODevice& fin);
88private:
89 State m_curState;
90 StringBuffer m_buffer;
91 StringBuffer m_temp;
92
93/* State nextState (char c);
94 Action nextAction (char c); */
95
96 void nextStep (char c, State* newState, Action* newAction);
97
98 void doOutput ();
99 void doHandleByteArray ();
100 uchar getByte();
101 uchar decode();
102
103protected:
104 virtual void parsingStarted();
105 virtual void parsingFinished();
106 virtual void parsingAborted();
107
108 virtual void gotComment (const char *value);
109 virtual void gotIntValue (int value);
110 virtual void gotDoubleValue (double value);
111 virtual void gotStringValue (const char *value);
112 virtual void gotToken (const char *value);
113 virtual void gotReference (const char *value);
114 virtual void gotBlockStart ();
115 virtual void gotBlockEnd ();
116 virtual void gotArrayStart ();
117 virtual void gotArrayEnd ();
118 virtual void gotByte (uchar value);
119 virtual void gotByteArray (const TQByteArray &data);
120};
121
122#endif
123