23 #include <QMessageBox>
26 #include <QStringList>
27 #include <QTextStream>
29 namespace Import_Rose {
59 QStringList
scan(
const QString& lin)
62 QString line = lin.trimmed();
66 const uint len = line.length();
67 bool inString =
false;
68 for (uint i = 0; i < len; ++i) {
73 result.append(lexeme);
77 }
else if (inString ||
78 c.isLetterOrNumber() || c ==
'_' || c ==
'@') {
81 if (!lexeme.isEmpty()) {
82 result.append(lexeme);
86 result.append(QString(c));
90 if (!lexeme.isEmpty())
91 result.append(lexeme);
100 QString first = l.first();
110 if (tokens.count() == 0)
112 if (tokens.last() ==
")") {
117 while (tokens.count() && tokens.last() ==
")") {
133 return s.contains(QRegExp(
"^[\\d\\-\"]"));
152 if (l.first() ==
"(")
162 if (l.first() ==
",")
165 if (l.first() ==
")")
167 while (l.count() && l.first() ==
")") {
179 while (!(line = stream.readLine()).isNull()) {
181 line = line.trimmed();
182 if (line.isEmpty() || line.startsWith(
')'))
184 if (line[0] !=
'|') {
185 uError() <<
loc() <<
"expecting '|' at start of verbatim text";
188 result += line.mid(1) +
'\n';
195 if (! line.isEmpty()) {
196 for (
int i = 0; i < line.length(); ++i) {
197 const QChar& clParenth = line[i];
198 if (clParenth !=
')') {
199 uError() <<
loc() <<
"expected ')', found: " << clParenth;
233 if (l.first() ==
"(")
235 if (l.first() !=
"value")
240 if (l.count() == 0) {
246 if (l.first() !=
")") {
247 uError() <<
loc() <<
"expecting closing parenthesis";
252 while (l.count() && l.first() ==
")") {
269 if (initialArgs.count() == 0) {
270 uError() <<
loc() <<
"initialArgs is empty";
274 QString type =
shift(initialArgs);
275 if (type ==
"object")
277 else if (type ==
"list")
280 uError() <<
loc() <<
"unknown node type " << type;
290 while (!(line = stream.readLine()).isNull()) {
292 line = line.trimmed();
295 QStringList tokens =
scan(line);
296 QString stringOrNodeOpener =
shift(tokens);
299 uError() <<
loc() <<
"unexpected line " << line;
304 name = stringOrNodeOpener;
305 if (tokens.count() == 0) {
319 stringOrNodeOpener =
shift(tokens);
320 }
else if (stringOrNodeOpener !=
"(") {
321 value.
string = stringOrNodeOpener;
325 if (tokens.count() && tokens.first() !=
")") {
327 <<
"NYI - immediate list entry with more than one item";
333 if (stringOrNodeOpener ==
"(") {
334 QString nxt = tokens.first();
337 }
else if (nxt ==
"value" || nxt.startsWith(
'\"')) {
341 if (value.
node == NULL)
355 value.
string = stringOrNodeOpener;
376 QTextStream stream(&file);
377 stream.setCodec(
"ISO 8859-1");
381 while (!(line = stream.readLine()).isNull()) {
383 if (line.contains(QRegExp(
"^\\s*\\(object Petal"))) {
385 while (!(line = stream.readLine()).isNull()) {
387 if (line.contains(
')')) {
389 line = line.replace(QLatin1String(
")"),QLatin1String(
""));
391 QStringList a = line.trimmed().split(QRegExp(
"\\s+"));
393 if (a[0] ==
"charSet" && a[1] ==
"134")
394 stream.setCodec(
"GB18030");
402 QRegExp objectRx(
"^\\s*\\(object ");
403 if (line.contains(objectRx)) {
405 QStringList initialArgs =
scan(line);
406 initialArgs.pop_front();
QStringList scan(const QString &lin)
Split a line into lexemes.
QString shift(QStringList &l)
Emulate perl shift().
bool isImmediateValue(QString s)
Immediate values are numbers or quoted strings.
bool checkClosing(QStringList &tokens)
Check for closing of one or more scopes.
QString extractValue(QStringList &l, QTextStream &stream)
Extract the stripped down value from a (value ...) element.
Rose petal node - parse tree for model import.
void setAttributes(NameValueList vl)
void setInitialArgs(const QStringList &args)
bool loadFromMDL(QIODevice &file)
Parse a file into the PetalNode internal tree representation and then create Umbrello objects by trav...
PetalNode * readAttributes(QStringList initialArgs, QTextStream &stream)
Read attributes of a node.
QString loc()
Auxiliary function for diagnostics: Return current location.
QPair< QString, StringOrNode > NameValue
QString extractImmediateValues(QStringList &l)
Extract immediate values out of `l'.
bool petalTree2Uml(PetalNode *root)
This is really an auxiliary method for loadFromMDL() but is kept in a separate file to reflect that i...
void methodName(const QString &m)
QString collectVerbatimText(QTextStream &stream)
Use `string' if it is not empty.
QList< NameValue > NameValueList