68
71
case State_CommentEncodedChar : return "encoded char (comment)";
69
72
case State_ByteArray2 : return "byte array (mode 2)";
70
73
default : return "unknown";
81
84
static Transition transitions[] = {
82
{ State_Comment, '\n', State_Start, Action_Output},
83
{ State_Comment, '\r', State_Start, Action_Output},
84
{ State_Comment, '\\', State_CommentEncodedChar, Action_InitTemp},
85
{ State_Comment, CATEGORY_ANY, State_Comment, Action_Copy},
86
{ State_Integer, CATEGORY_DIGIT, State_Integer, Action_Copy},
87
{ State_Integer, CATEGORY_WHITESPACE, State_Start, Action_Output},
88
{ State_Integer, '.', State_Float, Action_Copy},
89
{ State_Integer, ']', State_Start, Action_OutputUnget},
90
{ State_Integer, '}', State_Start, Action_OutputUnget},
91
{ State_Integer, '#', State_Byte, Action_Copy },
92
{ State_Integer, '/', State_Start, Action_OutputUnget },
93
{ State_Integer, '{', State_Start, Action_OutputUnget },
94
{ State_Integer, '%', State_Start, Action_OutputUnget },
95
{ State_Integer, CATEGORY_LETTERHEX, State_ByteArray2, Action_Copy },
96
{ State_Integer, CATEGORY_INTTOOLONG, State_ByteArray2, Action_Copy },
97
{ State_Integer, CATEGORY_ANY, State_Start, Action_Abort},
98
{ State_Float, CATEGORY_DIGIT, State_Float, Action_Copy},
99
{ State_Float, CATEGORY_WHITESPACE, State_Start, Action_Output},
100
{ State_Float, ']', State_Start, Action_OutputUnget},
101
{ State_Float, '}', State_Start, Action_OutputUnget},
102
{ State_Float, CATEGORY_ANY, State_Start, Action_Abort},
103
{ State_Token, CATEGORY_ALPHA, State_Token, Action_Copy},
104
{ State_Token, CATEGORY_DIGIT, State_Token, Action_Copy},
105
{ State_Token, CATEGORY_SPECIAL, State_Token, Action_Copy},
106
{ State_Token, '}', State_Start, Action_OutputUnget},
107
{ State_Token, ']', State_Start, Action_OutputUnget},
108
{ State_Token, '{', State_BlockStart, Action_Output},
109
{ State_Token, '}', State_BlockEnd, Action_Output},
110
{ State_Token, '/', State_Start, Action_OutputUnget},
111
{ State_Token, CATEGORY_WHITESPACE, State_Start, Action_Output},
112
{ State_Token, CATEGORY_ANY, State_Start, Action_Abort},
113
{ State_String, ')', State_Start, Action_Output},
114
{ State_String, '\\', State_StringEncodedChar, Action_InitTemp},
115
{ State_String, CATEGORY_ANY, State_String, Action_Copy},
85
{ State_Comment, '\n', State_Start, Action_Output},
86
{ State_Comment, '\r', State_Start, Action_Output},
87
{ State_Comment, '\\', State_CommentEncodedChar, Action_InitTemp},
88
{ State_Comment, CATEGORY_ANY, State_Comment, Action_Copy},
89
{ State_Integer, CATEGORY_DIGIT, State_Integer, Action_Copy},
90
{ State_Integer, CATEGORY_WHITESPACE, State_Start, Action_Output},
91
{ State_Integer, '.', State_Float, Action_Copy},
92
{ State_Integer, ']', State_Start, Action_OutputUnget},
93
{ State_Integer, '}', State_Start, Action_OutputUnget},
94
{ State_Integer, '#', State_Byte, Action_Copy },
95
{ State_Integer, '/', State_Start, Action_OutputUnget },
96
{ State_Integer, '{', State_Start, Action_OutputUnget },
97
{ State_Integer, '%', State_Start, Action_OutputUnget },
98
{ State_Integer, CATEGORY_LETTERHEX, State_ByteArray2, Action_Copy },
99
{ State_Integer, CATEGORY_INTTOOLONG, State_ByteArray2, Action_Copy },
100
{ State_Integer, CATEGORY_ANY, State_Start, Action_Abort},
101
{ State_Float, CATEGORY_DIGIT, State_Float, Action_Copy},
102
{ State_Float, CATEGORY_WHITESPACE, State_Start, Action_Output},
103
{ State_Float, ']', State_Start, Action_OutputUnget},
104
{ State_Float, '}', State_Start, Action_OutputUnget},
105
{ State_Float, CATEGORY_ANY, State_Start, Action_Abort},
106
{ State_Token, CATEGORY_ALPHA, State_Token, Action_Copy},
107
{ State_Token, CATEGORY_DIGIT, State_Token, Action_Copy},
108
{ State_Token, CATEGORY_SPECIAL, State_Token, Action_Copy},
109
{ State_Token, '}', State_Start, Action_OutputUnget},
110
{ State_Token, ']', State_Start, Action_OutputUnget},
111
{ State_Token, '{', State_BlockStart, Action_Output},
112
{ State_Token, '}', State_BlockEnd, Action_Output},
113
{ State_Token, '/', State_Start, Action_OutputUnget},
114
{ State_Token, CATEGORY_WHITESPACE, State_Start, Action_Output},
115
{ State_Token, CATEGORY_ANY, State_Start, Action_Abort},
116
{ State_String, ')', State_Start, Action_Output},
117
{ State_String, '\\', State_StringEncodedChar, Action_InitTemp},
118
{ State_String, CATEGORY_ANY, State_String, Action_Copy},
116
119
// { State_Array, CATEGORY_ALPHA, State_Array, Action_Copy},
117
120
// { State_Array, CATEGORY_DIGIT, State_Array, Action_Copy},
118
121
// { State_Array, ' ', State_Array, Action_Copy},
119
{ State_BlockStart, CATEGORY_ANY, State_Start, Action_OutputUnget },
120
{ State_BlockEnd, CATEGORY_ANY, State_Start, Action_OutputUnget },
121
{ State_ArrayStart, CATEGORY_ANY, State_Start, Action_OutputUnget },
122
{ State_ArrayEnd, CATEGORY_ANY, State_Start, Action_OutputUnget },
123
{ State_Reference, '#', State_Reference, Action_Copy },
124
{ State_Reference, CATEGORY_ALPHA, State_Reference, Action_Copy },
125
{ State_Reference, CATEGORY_DIGIT, State_Reference, Action_Copy },
126
{ State_Reference, CATEGORY_SPECIAL, State_Reference, Action_Copy },
127
{ State_Reference, CATEGORY_ANY, State_Start, Action_OutputUnget },
128
{ State_Byte, '/', State_Start, Action_OutputUnget },
129
{ State_Byte, CATEGORY_DIGIT, State_Byte, Action_Copy},
130
{ State_Byte, CATEGORY_ALPHA, State_Byte, Action_Copy},
131
{ State_Byte, CATEGORY_WHITESPACE, State_Start, Action_Output},
132
{ State_ByteArray, '>', State_Start, Action_Output },
133
{ State_ByteArray, CATEGORY_ALPHA, State_ByteArray, Action_Copy },
134
{ State_ByteArray, CATEGORY_DIGIT, State_ByteArray, Action_Copy },
135
{ State_ByteArray, CATEGORY_WHITESPACE, State_ByteArray, Action_Ignore },
136
{ State_ByteArray, CATEGORY_ANY, State_Start, Action_Abort },
137
{ State_StringEncodedChar, '\\', State_String, Action_Copy},
138
{ State_StringEncodedChar, CATEGORY_DIGIT, State_StringEncodedChar, Action_CopyTemp},
139
{ State_StringEncodedChar, CATEGORY_ANY, State_String, Action_DecodeUnget},
140
{ State_CommentEncodedChar, '\\', State_Comment, Action_Copy},
141
{ State_CommentEncodedChar, CATEGORY_DIGIT, State_CommentEncodedChar, Action_CopyTemp},
142
{ State_CommentEncodedChar, CATEGORY_ANY, State_Comment, Action_DecodeUnget},
143
{ State_ByteArray2, '\n', State_Start, Action_Output},
144
{ State_ByteArray2, '\r', State_Start, Action_Output},
145
{ State_ByteArray2, '}', State_Start, Action_ByteArraySpecial},
146
{ State_ByteArray2, CATEGORY_WHITESPACE, State_Start, Action_Output},
147
{ State_ByteArray2, CATEGORY_DIGIT, State_ByteArray2, Action_Copy},
148
{ State_ByteArray2, CATEGORY_LETTERHEX, State_ByteArray2, Action_Copy},
149
{ State_ByteArray2, CATEGORY_ALPHA, State_Token, Action_Copy},
150
{ State_ByteArray2, CATEGORY_ANY, State_Start, Action_Abort},
151
{ State_Start, '%', State_Comment, Action_Ignore},
152
{ State_Start, CATEGORY_DIGIT, State_Integer, Action_Copy},
153
{ State_Start, '-', State_Integer, Action_Copy},
154
{ State_Start, '+', State_Integer, Action_Copy},
155
{ State_Start, '.', State_Float, Action_Copy},
156
{ State_Start, '/', State_Reference, Action_Ignore },
157
{ State_Start, '(', State_String, Action_Ignore},
158
{ State_Start, '{', State_BlockStart, Action_Copy},
159
{ State_Start, '}', State_BlockEnd, Action_Copy},
160
{ State_Start, '[', State_ArrayStart, Action_Copy},
161
{ State_Start, ']', State_ArrayEnd, Action_Copy},
162
{ State_Start, '<', State_ByteArray, Action_Ignore},
163
{ State_Start, CATEGORY_ALPHA, State_Token, Action_Copy},
164
{ State_Start, CATEGORY_WHITESPACE, State_Start, Action_Output},
165
{ State_Start, CATEGORY_SPECIAL, State_Token, Action_Copy},
166
{ State_Start, CATEGORY_LETTERHEX, State_ByteArray2, Action_Copy},
167
{ State_Start, CATEGORY_ANY, State_Start, Action_Abort},
168
{ State_Start, STOP, State_Start, Action_Abort}
122
{ State_BlockStart, CATEGORY_ANY, State_Start, Action_OutputUnget },
123
{ State_BlockEnd, CATEGORY_ANY, State_Start, Action_OutputUnget },
124
{ State_ArrayStart, CATEGORY_ANY, State_Start, Action_OutputUnget },
125
{ State_ArrayEnd, CATEGORY_ANY, State_Start, Action_OutputUnget },
126
{ State_Reference, '#', State_Reference, Action_Copy },
127
{ State_Reference, CATEGORY_ALPHA, State_Reference, Action_Copy },
128
{ State_Reference, CATEGORY_DIGIT, State_Reference, Action_Copy },
129
{ State_Reference, CATEGORY_SPECIAL, State_Reference, Action_Copy },
130
{ State_Reference, CATEGORY_ANY, State_Start, Action_OutputUnget },
131
{ State_Byte, '/', State_Start, Action_OutputUnget },
132
{ State_Byte, CATEGORY_DIGIT, State_Byte, Action_Copy},
133
{ State_Byte, CATEGORY_ALPHA, State_Byte, Action_Copy},
134
{ State_Byte, CATEGORY_WHITESPACE, State_Start, Action_Output},
135
{ State_ByteArray, '>', State_Start, Action_Output },
136
{ State_ByteArray, CATEGORY_ALPHA, State_ByteArray, Action_Copy },
137
{ State_ByteArray, CATEGORY_DIGIT, State_ByteArray, Action_Copy },
138
{ State_ByteArray, CATEGORY_WHITESPACE, State_ByteArray, Action_Ignore },
139
{ State_ByteArray, CATEGORY_ANY, State_Start, Action_Abort },
140
{ State_StringEncodedChar, '\\', State_String, Action_Copy},
141
{ State_StringEncodedChar, CATEGORY_DIGIT, State_StringEncodedChar, Action_CopyTemp},
142
{ State_StringEncodedChar, CATEGORY_ANY, State_String, Action_DecodeUnget},
143
{ State_CommentEncodedChar, '\\', State_Comment, Action_Copy},
144
{ State_CommentEncodedChar, CATEGORY_DIGIT, State_CommentEncodedChar, Action_CopyTemp},
145
{ State_CommentEncodedChar, CATEGORY_ANY, State_Comment, Action_DecodeUnget},
146
{ State_ByteArray2, '\n', State_Start, Action_Output},
147
{ State_ByteArray2, '\r', State_Start, Action_Output},
148
{ State_ByteArray2, '}', State_Start, Action_ByteArraySpecial},
149
{ State_ByteArray2, CATEGORY_WHITESPACE, State_Start, Action_Output},
150
{ State_ByteArray2, CATEGORY_DIGIT, State_ByteArray2, Action_Copy},
151
{ State_ByteArray2, CATEGORY_LETTERHEX, State_ByteArray2, Action_Copy},
152
{ State_ByteArray2, CATEGORY_ALPHA, State_Token, Action_Copy},
153
{ State_ByteArray2, CATEGORY_ANY, State_Start, Action_Abort},
154
{ State_Start, '%', State_Comment, Action_Ignore},
155
{ State_Start, CATEGORY_DIGIT, State_Integer, Action_Copy},
156
{ State_Start, '-', State_Integer, Action_Copy},
157
{ State_Start, '+', State_Integer, Action_Copy},
158
{ State_Start, '.', State_Float, Action_Copy},
159
{ State_Start, '/', State_Reference, Action_Ignore },
160
{ State_Start, '(', State_String, Action_Ignore},
161
{ State_Start, '{', State_BlockStart, Action_Copy},
162
{ State_Start, '}', State_BlockEnd, Action_Copy},
163
{ State_Start, '[', State_ArrayStart, Action_Copy},
164
{ State_Start, ']', State_ArrayEnd, Action_Copy},
165
{ State_Start, '<', State_ByteArray, Action_Ignore},
166
{ State_Start, CATEGORY_ALPHA, State_Token, Action_Copy},
167
{ State_Start, CATEGORY_WHITESPACE, State_Start, Action_Output},
168
{ State_Start, CATEGORY_SPECIAL, State_Token, Action_Copy},
169
{ State_Start, CATEGORY_LETTERHEX, State_ByteArray2, Action_Copy},
170
{ State_Start, CATEGORY_ANY, State_Start, Action_Abort},
171
{ State_Start, STOP, State_Start, Action_Abort}
176
bool AILexer::parse (QIODevice& fin){
180
m_curState = State_Start;
181
bool AILexer::parse(QIODevice& fin)
186
m_curState = State_Start;
190
while (!fin.atEnd()) {
188
193
// qDebug ("got %c", c);
193
nextStep (c, &newState, &action);
200
case Action_CopyOutput :
207
case Action_OutputUnget :
215
qWarning ( "state %s / %s char %c (%d)" , statetoa(m_curState), statetoa(newState), c, c );
219
case Action_InitTemp :
222
case Action_CopyTemp :
225
case Action_DecodeUnget :
226
m_buffer.append (decode());
229
// in Postscript Quelltext: Kombination F}
230
case Action_ByteArraySpecial :
231
m_curState = State_Token;
236
qWarning ( "unknown action: %d ", action);
198
nextStep(c, &newState, &action);
204
case Action_CopyOutput :
211
case Action_OutputUnget :
219
qWarning("state %s / %s char %c (%d)" , statetoa(m_curState), statetoa(newState), c, c);
223
case Action_InitTemp :
226
case Action_CopyTemp :
229
case Action_DecodeUnget :
230
m_buffer.append(decode());
233
// in Postscript Quelltext: Kombination F}
234
case Action_ByteArraySpecial :
235
m_curState = State_Token;
240
qWarning("unknown action: %d ", action);
243
m_curState = newState;
239
m_curState = newState;
246
void AILexer::doOutput ()
250
void AILexer::doOutput()
248
if (m_buffer.length() == 0) return;
252
if (m_buffer.length() == 0) return;
253
switch (m_curState) {
251
254
case State_Comment :
252
gotComment (m_buffer.latin1());
255
gotComment(m_buffer.toLatin1());
254
257
case State_Integer :
255
gotIntValue (m_buffer.toInt());
258
gotIntValue(m_buffer.toInt());
257
260
case State_Float :
258
gotDoubleValue (m_buffer.toFloat());
261
gotDoubleValue(m_buffer.toFloat());
260
263
case State_String :
261
gotStringValue (m_buffer.latin1());
264
gotStringValue(m_buffer.toLatin1());
263
266
case State_Token :
264
gotToken (m_buffer.latin1());
267
gotToken(m_buffer.toLatin1());
266
269
case State_Reference :
267
gotReference (m_buffer.latin1());
270
gotReference(m_buffer.toLatin1());
269
272
case State_BlockStart :
272
275
case State_BlockEnd :
275
278
case State_Start :
277
280
case State_ArrayStart :
280
283
case State_ArrayEnd :
283
286
case State_Byte :
286
289
case State_ByteArray :
287
290
case State_ByteArray2 :
288
doHandleByteArray ();
291
qWarning ( "unknown state: %d", m_curState );
297
void AILexer::gotComment (const char *value) {
298
qDebug ( "gotComment: %s ", value );
301
void AILexer::gotIntValue (int value) {
302
qDebug ( "gotInt: %d ", value );
305
void AILexer::gotDoubleValue (double value) {
306
qDebug ( "gotDouble: %f ", value );
309
void AILexer::gotStringValue (const char *value) {
310
qDebug ( "gotString: %s ", value );
313
void AILexer::gotToken (const char *value) {
314
qDebug ( "gotToken: %s ", value );
317
void AILexer::gotReference (const char *value) {
318
qDebug ( "gotReference: %s ", value );
321
void AILexer::gotBlockStart (){
322
qDebug ( "gotBlockStart" );
325
void AILexer::gotBlockEnd (){
326
qDebug ( "gotBlockEnd" );
329
void AILexer::gotArrayStart (){
330
qDebug ( "gotArrayStart" );
333
void AILexer::gotArrayEnd (){
334
qDebug ( "gotArrayEnd" );
337
void AILexer::parsingStarted() {
338
qDebug ( "parsing started" );
341
void AILexer::parsingFinished() {
342
qDebug ( "parsing finished" );
345
void AILexer::parsingAborted() {
346
qDebug ( "parsing aborted" );
349
void AILexer::gotByte (uchar value) {
350
qDebug ( "got byte %d" , value );
353
void AILexer::gotByteArray (const QByteArray &data) {
354
qDebug ( "got byte array" );
355
/* for ( uint i = 0; i < data.size(); i++ )
357
uchar value = data[i];
358
qDebug( "%d: %x", i, value );
360
qDebug ( "/byte array" ); */
365
void AILexer::nextStep (char c, State *newState, Action *newAction) {
369
Transition trans = transitions[i];
371
if (trans.c == STOP) {
372
*newState = trans.newState;
373
*newAction = trans.action;
294
qWarning("unknown state: %d", m_curState);
379
if (trans.oldState == m_curState) {
381
case CATEGORY_WHITESPACE : found = isspace(c); break;
382
case CATEGORY_ALPHA : found = isalpha(c); break;
383
case CATEGORY_DIGIT : found = isdigit(c); break;
384
case CATEGORY_SPECIAL : found = isSpecial(c); break;
385
case CATEGORY_LETTERHEX : found = isletterhex(c); break;
386
case CATEGORY_INTTOOLONG : found = m_buffer.length() > MAX_INTLEN; break;
387
case CATEGORY_ANY : found = true; break;
388
default : found = (trans.c == c);
300
void AILexer::gotComment(const char *value)
302
qDebug("gotComment: %s ", value);
305
void AILexer::gotIntValue(int value)
307
qDebug("gotInt: %d ", value);
310
void AILexer::gotDoubleValue(double value)
312
qDebug("gotDouble: %f ", value);
315
void AILexer::gotStringValue(const char *value)
317
qDebug("gotString: %s ", value);
320
void AILexer::gotToken(const char *value)
322
qDebug("gotToken: %s ", value);
325
void AILexer::gotReference(const char *value)
327
qDebug("gotReference: %s ", value);
330
void AILexer::gotBlockStart()
332
qDebug("gotBlockStart");
335
void AILexer::gotBlockEnd()
337
qDebug("gotBlockEnd");
340
void AILexer::gotArrayStart()
342
qDebug("gotArrayStart");
345
void AILexer::gotArrayEnd()
347
qDebug("gotArrayEnd");
350
void AILexer::parsingStarted()
352
qDebug("parsing started");
355
void AILexer::parsingFinished()
357
qDebug("parsing finished");
360
void AILexer::parsingAborted()
362
qDebug("parsing aborted");
365
void AILexer::gotByte(uchar value)
367
qDebug("got byte %d" , value);
370
void AILexer::gotByteArray(const QByteArray &data)
372
qDebug("got byte array");
373
/* for ( uint i = 0; i < data.size(); i++ )
375
uchar value = data[i];
376
qDebug( "%d: %x", i, value );
392
*newState = trans.newState;
393
*newAction = trans.action;
378
qDebug ( "/byte array" ); */
383
void AILexer::nextStep(char c, State *newState, Action *newAction)
388
Transition trans = transitions[i];
390
if (trans.c == STOP) {
391
*newState = trans.newState;
392
*newAction = trans.action;
398
if (trans.oldState == m_curState) {
400
case CATEGORY_WHITESPACE : found = isspace(c); break;
401
case CATEGORY_ALPHA : found = isalpha(c); break;
402
case CATEGORY_DIGIT : found = isdigit(c); break;
403
case CATEGORY_SPECIAL : found = isSpecial(c); break;
404
case CATEGORY_LETTERHEX : found = isletterhex(c); break;
405
case CATEGORY_INTTOOLONG : found = m_buffer.length() > MAX_INTLEN; break;
406
case CATEGORY_ANY : found = true; break;
407
default : found = (trans.c == c);
411
*newState = trans.newState;
412
*newAction = trans.action;
423
void AILexer::doHandleByteArray()
425
// Special case - too short
426
if (m_buffer.length() < MIN_HEXCHARS) {
427
gotToken(m_buffer.toLatin1());
404
void AILexer::doHandleByteArray ()
406
// Special case - too short
407
if (m_buffer.length () < MIN_HEXCHARS)
409
gotToken (m_buffer.latin1());
416
QByteArray data (m_buffer.length() >> 1);
418
while (strIdx < m_buffer.length())
420
const QString &item = m_buffer.mid (strIdx, 2);
421
uchar val = item.toShort(NULL, 16);
422
data[arrayIdx] = val;
434
QByteArray data(m_buffer.length() >> 1);
436
while (strIdx < m_buffer.length()) {
437
const QString &item = m_buffer.mid(strIdx, 2);
438
uchar val = item.toShort(NULL, 16);
439
data[arrayIdx] = val;
430
447
uchar AILexer::getByte()
432
// qDebug ("convert string to byte (%s)", m_buffer.latin1());
434
QStringList list = QStringList::split ("#", m_buffer.toString());
435
int radix = list[0].toShort();
436
uchar value = list[1].toShort (NULL, radix);
449
// qDebug ("convert string to byte (%s)", m_buffer.toLatin1());
451
QStringList list = QStringList::split("#", m_buffer.toString());
452
int radix = list[0].toShort();
453
uchar value = list[1].toShort(NULL, radix);
441
458
uchar AILexer::decode()
443
uchar value = m_temp.toString().toShort(NULL, 8);
460
uchar value = m_temp.toString().toShort(NULL, 8);
444
461
// qDebug ("got encoded char %c",value);
448
465
/* StringBuffer implementation */