1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
//-*-C++-*-
/*
**************************************************************************
description
--------------------
copyright : (C) 2000-2003 by Andreas Zehender
email : zehender@kde.org
**************************************************************************
**************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
**************************************************************************/
#ifndef PMPARSER_H
#define PMPARSER_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <kurl.h>
#include <tqcstring.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqvaluelist.h>
#include <tqptrdict.h>
#include <tqptrlist.h>
#include "pmobject.h"
#include "pmsymboltable.h"
#include "pmvalue.h"
#include "pmerrordialog.h"
class TQTextStream;
class TQIODevice;
class PMScanner;
class PMPart;
class PMSymbolTable;
enum PMPMessage { PMMClockDefault = 1, PMMClockDeltaDefault = 2,
PMMSpecialRawComment = 4 };
/**
* Base class for kpovmodeler parsers.
*/
class PMParser
{
public:
/**
* Parser that parses the device
*/
PMParser( PMPart* part, TQIODevice* device );
/**
* Parser that parses the byte array
*/
PMParser( PMPart* part, const TQByteArray& array );
/**
* Deletes the parser
*/
virtual ~PMParser( );
/**
* Quickly scans the top level objects. Appends all top level object
* types to the list.
*/
virtual void quickParse( TQStringList& /*list*/ ) { };
/**
* Returns true, if the parser can quickly scan the top level objects.
*/
virtual bool canQuickParse( ) const { return false; }
/**
* Parses the device.
*
* Appends all parsed objects to the list.
*
* parent is the object where the parsed objects will be inserted as
* children behind the object after. These parameters are used to check
* the consistency of declares and links.
*
* Set parent and after to 0 if and only if a document is parsed/opened.
*/
void parse( PMObjectList* list, PMObject* parent,
PMObject* after );
/**
* Returns the messages of the parser
*/
PMMessageList messages( ) const { return m_messages; }
/**
* Returns true if there were errors during parsing
*/
bool errors( ) const { return m_errors > 0; }
/**
* Returns true if there were warnings during parsing
*/
bool warnings( ) const { return m_warnings > 0; }
/**
* Returns true, if a fatal error occurred or no object could be
* successfully parsed and it doesn't make sense to continue
*/
bool fatal( ) const { return m_bFatalError; }
/**
* Returns a bitwise combination of @ref PMErrorFlags constants
*/
int errorFlags( ) const;
/**
* returns the maximum number of errors
*/
static unsigned maxErrors( ) { return s_maxErrors; }
/**
* sets the maximum number of errors to m
*/
static void setMaxErrors( unsigned m ) { s_maxErrors = m; }
/**
* returns the maximum number of warnings
*/
static unsigned maxWarnings( ) { return s_maxWarnings; }
/**
* sets the maximum number of warnings to m
*/
static void setMaxWarnings( unsigned m ) { s_maxWarnings = m; }
/**
* Adds an error to the message string
*/
void printError( const TQString& msg );
/**
* Adds the error "'<str>' expected, found <token> instead" to the message string
*/
void printExpected( const TQString& str, const char* token );
/**
* Adds the error "'<c>' expected" to the message string
*/
void printExpected( const char c, const char* token );
/**
* Adds the error "Unexpected token '<str>', found <token> instead" to the message string
*/
void printUnexpected( const TQString& str );
/**
* Adds a warning to the message string
*/
void printWarning( const TQString& msg );
/**
* Adds an info to the message string
*/
void printInfo( const TQString& msg );
/**
* Adds the message to the message string. Type is "error", "warning",
* "info" or "scanner error"
*/
void printMessage( const TQString& type, const TQString& msg );
/**
* Prints a messages that should only reported once
*/
void printMessage( const PMPMessage messageNum );
/**
* Sets the fatal error flag
*/
void setFatalError( ) { m_bFatalError = true; }
/**
* Sets the current line number
*/
void setCurrentLine( int lineNumber ) { m_lineNum = lineNumber; }
/**
* Returns the declare object with id, if it exists and is declared at
* the current parse position, otherwise 0
*/
PMDeclare* checkLink( const TQString& id );
/**
* Checks the id of the declare. If there is already a declare with
* the same id, the id of the object is renamed.
*
* Inserts the object into the symbol table.*/
void checkID( PMDeclare* obj );
/**
* Checks the id of the value declare (constant, vector or color).
* If there is already a declare with
* the same id, the id of the value is renamed.
*
* Inserts the object into the symbol table.*/
void checkID( const TQString& id, const PMValue& v );
/**
* Returns the symbol with id id or 0 if the id is undeclared
*/
PMSymbol* getSymbol( const TQString& id ) const;
/**
* Tries to insert obj as child of parent. If parent is 0, the object
* will be inserted in the list of top level objects.
*
* Returns true if the object could be inserted.
*/
bool insertChild( PMObject* obj, PMObject* parent );
protected:
/**
* Top level parse function.
*
* Overwrite this function in a specific parser.
*/
virtual void topParse( ) = 0;
protected:
/**
* Pointer to the part
*/
PMPart* m_pPart;
/**
* parent object where the parsed top level objects
* will be inserted _later_ (not from the parser) as children
*/
const PMObject* m_pTopParent;
const PMObject* m_pAfter;
/**
* The list where the parsed objects are stored
*/
PMObjectList* m_pResultList;
/**
* The TQIODevice
*/
TQIODevice* m_pDevice;
/**
* True, if the device was created by the parser
*/
bool m_bDeviceCreated;
private:
/**
* Initializes the parser
*/
void init( );
/**
* The parser output (errors, warnings...)
*/
PMMessageList m_messages;
/**
* A dictionary object -> message
*/
TQPtrDict< TQPtrList<PMMessage> > m_messageDict;
/**
* Number of warnings during parsing
*/
unsigned int m_warnings;
/**
* Number of errors during parsing
*/
unsigned int m_errors;
/**
* Flag for fatal errors
*/
bool m_bFatalError;
/**
* maximum number of errors
*/
static unsigned int s_maxErrors;
/**
* maximum number of warnings
*/
static unsigned int s_maxWarnings;
/**
* Already shown warnings or errors, that are reported only once
*/
int m_shownMessages;
/**
* The current line number
*/
int m_lineNum;
/**
* List of renamed declares
*/
TQPtrList<PMSymbol> m_renamedObjectSymbols;
/**
* Dictionary of symbol names, that can be linked
*/
TQDict<bool> m_okDeclares;
PMObject* m_pNextCheckDeclare;
/**
* Symbol table used during parsing. The symbol table of the part
* will not be changed.
*/
PMSymbolTable m_pLocalST;
};
#endif
|